5

I have anaconda environments for python2 and python3 as I have code written in the different versions

In spacemacs (with python layer installed), when I open ipython (SPC m s i) it starts with my default environment (python 3)

Is there a way to choose which version of python I run my code with? I've tried opening a shell with activate python2 to activate my other environment, but ipython in emacs still opens with my default

One way I've found is to activate the environment is SPC m V a then navigate to the directory where the venv is, but this is quite tedious as the python script and venv are often on different drives so it takes a fair bit of typing/tabbing to get to the venv directory

Is there a quicker way?

Simon
  • 411
  • 6
  • 15

2 Answers2

9

Basically, this is a duplicate of this question. Reproducing the proposed behavior with spacemacs, I changed my user-init to:

(defun dotspacemacs/user-init ()
  (setenv "WORKON_HOME" "/home/<username>/.local/bin/anaconda3/envs")
)

After reloading my .spacemacs file with SPC f e R, I'm immediately able to use , V w and select environments from my anaconda installation.

Michael Gecht
  • 206
  • 2
  • 4
0

Full process to make running SPC m c c inside a conda env work on Windows:

# install both layers in the dotfile
   dotspacemacs-configuration-layers
   '(
... add the 2 lines below
(python :variables python-shell-interpreter "c:/path/to/conda/envs/ds/python.exe")
(conda :variables conda-anaconda-home "c:/path/to/conda")
...

# setup pyvenv in user-init
(defun dotspacemacs/user-init ()
... add the 2 lines below
  (setenv "WORKON_HOME" "d:/progs/mambaforge/envs")
  (pyvenv-mode 1)
...
  )

# then open python file and make sure all the modes are active (run them)
python-mode
anaconda-mode
pyvenv-mode

# select environment in pyvenv and conda
pyvenv-workon
conda-env-activate

Finally SPC m c c runs inside the environment.

Simon
  • 1