Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use conda to create separate python environments, each with a different $PYTHONPATH

I would like to use conda to create different environments, each with a different $PYTHONPATH. Currently, I have to change the environment variables each time in my .bashrc. Is there a simple way of creating multiple python environments via conda, such that I can seamless switch (via source activate) and have the corresponding $PYTHONPATHs update automatically?

like image 733
vgoklani Avatar asked Jun 13 '14 20:06

vgoklani


People also ask

Can you have multiple conda environments?

While you can have multiple environments that contain different versions of Python at the same time on the same computer, you can't set up 32- and 64-bit environments using the same Conda management system.

How do you switch between conda environments?

You can always use conda activate or conda deactivate to switch between your environments. You can directly activate the environment you wish to use by using conda activate . conda deactivate will deactivate your current active environment and change to the default environment which is the base environment.

Does conda set Pythonpath?

There is no need to set the PYTHONPATH environment variable. To see if the conda installation of Python is in your PATH variable: On macOS and Linux, open the terminal and run echo $PATH . On Windows, open an Anaconda Prompt and run echo %PATH% .


1 Answers

You can specify the PYTHONPATH before you execute any script, which would be easier than changing your .bashrc

For example, to put the current working directory on the path before executing any script, you can do this

PYTHONPATH=`pwd`: python

If you didn't want to overwrite the entire path, but just append to it

PYTHONPATH=`pwd`:$PYTHONPATH python
like image 77
jeffmax Avatar answered Sep 27 '22 21:09

jeffmax