bash 如何将 PYTHONPATH 设置为多个文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39682688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set PYTHONPATH to multiple folders
提问by alphanumeric
In ~/.bash_profile
file (OS X) I've set PYTHONPATH to point to two folders:
在~/.bash_profile
文件 (OS X) 中,我将 PYTHONPATH 设置为指向两个文件夹:
export PYTHONPATH=/Applications/python/common:$PYTHONPATH
export PYTHONPATH=/Applications/sitecustomize:$PYTHONPATH
Even while sitecustomize
folder is set on a second line (after /common
)
the first path is ignored and I am not able to import any module from the path defined in a first line. What needs to be revised in above syntax to make both folders PYTHONPATHish to Python?
即使sitecustomize
文件夹设置在第二行(之后/common
),第一个路径也被忽略,我无法从第一行中定义的路径导入任何模块。需要在上面的语法中修改什么才能使两个文件夹 PYTHONPATHish 都变成 Python?
采纳答案by Chris Townsend
Append your paths so there is only one PYTHONPATH.
附加您的路径,以便只有一个 PYTHONPATH。
PYTHONPATH="/Applications/python/common:/Applications/sitecustomize:$PYTHONPATH"
export PYTHONPATH
Then source ~/.bash_profile
然后 source ~/.bash_profile
OR import them into your Python script (this would only work for the script added to):
或将它们导入您的 Python 脚本(这仅适用于添加到的脚本):
import sys
sys.path.append("/Applications/python/common")
sys.path.append("/Applications/sitecustomize")