本文介绍了如何使用conda创建单独的python环境,每个环境具有不同的$ PYTHONPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用conda来创建不同的环境,每个环境都具有不同的$ PYTHONPATH.当前,我每次都必须在.bashrc中更改环境变量.是否有一种简单的方法可以通过conda创建多个python环境,从而使我可以无缝切换(通过源激活)并自动更新相应的$ PYTHONPATHs?

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?

推荐答案

您可以在执行任何脚本之前指定PYTHONPATH,这比更改.bashrc容易

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

这篇关于如何使用conda创建单独的python环境,每个环境具有不同的$ PYTHONPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 22:35