添加到python路径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路径mac os x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!