如何将PYTHONPATH设置为多个文件夹 [英] How to set PYTHONPATH to multiple folders
问题描述
在〜/.bash_profile
文件(OS X)中,我将PYTHONPATH设置为指向两个文件夹:
In ~/.bash_profile
file (OS X) I've set PYTHONPATH to point to two folders:
export PYTHONPATH=/Applications/python/common:$PYTHONPATH
export PYTHONPATH=/Applications/sitecustomize:$PYTHONPATH
即使将 sitecustomize
文件夹设置在第二行上(在/common
之后)第一条路径被忽略,我无法从第一行中定义的路径导入任何模块.要使两个文件夹都PYTHONPATH都变为Python,需要对上述语法进行哪些修改?
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?
推荐答案
附加路径,因此只有一个PYTHONPATH.
Append your paths so there is only one PYTHONPATH.
PYTHONPATH="/Applications/python/common:/Applications/sitecustomize:$PYTHONPATH"
export PYTHONPATH
然后 source〜/.bash_profile
或将它们导入到您的Python脚本中(这仅适用于添加到脚本中的脚本):
OR import them into your Python script (this would only work for the script added to):
import sys
sys.path.append("/Applications/python/common")
sys.path.append("/Applications/sitecustomize")
这篇关于如何将PYTHONPATH设置为多个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!