简体   繁体   中英

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?

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

$PYTHONPATH can be changed when a conda environment is activated or deactivated, the same way it can be done with other environment variables. The following section in condo documentation describes how to specify this behaviour: Saved environment variables .

For example, you can add the following line to the activation script

export PYTHONPATH="What_you_want_to_add:$PYTHONPATH"

and so on ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM