添加到python path mac os x [英] Add to python path mac os x
问题描述
我想
import sys
sys.path.append("/home/me/mydir")
正在将目录附加到我的pythonpath
is appending a dir to my pythonpath
如果我打印sys.path,我的目录就在其中.
if I print sys.path my dir is in there.
然后我打开一个新命令,它不再存在.
Then I open a new command and it is not there anymore.
但是Python不能以某种方式导入我保存在该目录中的模块.
But somehow Python cant import modules I saved in that dir.
我在做什么错了?
我阅读了.profile或.bash_profile将解决问题.
I read .profile or .bash_profile will do the trick.
我是否必须添加:
PATH="/Me//Documents/mydir:$PYTHONPATH"
export PATH
要使其正常工作?
推荐答案
对sys.path
的修改仅适用于该Python解释器的生命.如果要永久执行此操作,则需要修改PYTHONPATH
环境变量:
Modifications to sys.path
only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH
environment variable:
PYTHONPATH="/Me/Documents/mydir:$PYTHONPATH"
export PYTHONPATH
请注意,PATH
是可执行文件的系统路径,它是完全独立的.
Note that PATH
is the system path for executables, which is completely separate.
**您可以在~/.bash_profile
中编写以上内容,并使用source ~/.bash_profile
**You can write the above in ~/.bash_profile
and the source it using source ~/.bash_profile
这篇关于添加到python path mac os x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!