How to use conda to create separate python environ

2020-02-29 02:07发布

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?

2条回答
小情绪 Triste *
2楼-- · 2020-02-29 02:31

$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 ...

查看更多
地球回转人心会变
3楼-- · 2020-02-29 02:45

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
查看更多
登录 后发表回答