简体   繁体   English

如何使用conda创建单独的python环境,每个环境都有不同的$ PYTHONPATH

[英]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. 我想用conda创建不同的环境,每个环境都有不同的$ PYTHONPATH。 Currently, I have to change the environment variables each time in my .bashrc. 目前,我必须每次在.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? 有没有一种通过conda创建多个python环境的简单方法,这样我可以无缝切换(通过源激活)并自动更新相应的$ PYTHONPATHs?

You can specify the PYTHONPATH before you execute any script, which would be easier than changing your .bashrc 您可以在执行任何脚本之前指定PYTHONPATH,这比更改.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. 激活或停用conda环境时,可以更改$ PYTHONPATH,与使用其他环境变量完成相同。 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 ... 等等 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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