![PYTHONPATH 在 Bash Shell 中设置为不正确的值](https://linux22.com/image/1504049/PYTHONPATH%20%E5%9C%A8%20Bash%20Shell%20%E4%B8%AD%E8%AE%BE%E7%BD%AE%E4%B8%BA%E4%B8%8D%E6%AD%A3%E7%A1%AE%E7%9A%84%E5%80%BC.png)
操作系统:macOS Sierra Beta 6 Python:2.7 Shell:Fish
我在正确设置 PYTHONPATH 环境变量时遇到问题。
在我的 fish_config 文件中,我有以下行设置 PYTHONPATH:
set -gx PYTHONPATH "/opt/additionalPath" "/usr/local/lib/python2.7/site-packages";
但是当我启动 python 时,当我尝试查看路径时得到这个输出:
>>> import sys
>>> print sys.path
['', '/opt/additionalPath\x1e/usr/local/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
>>>
注意我添加的路径之间的 \x1e。
如果我从 fish 启动 bash shell 并回显 $PYTHONPATH,我会得到以下输出:
/opt/additionalPath/usr/local/lib/python2.7/site-packages
我知道这些路径应该用冒号分隔,但我不知道在哪里这样做。我的理论是 bash shell 中的某些东西正在设置 fish shell 中的路径,但我没有主意了。
任何帮助将非常感激。
答案1
您不能在 fish for 中使用列表PYTHONPATH
,而必须使用单个字符串作为:
分隔符,就像在 bash 中一样:
set -gx PYTHONPATH "/opt/additionalPath:/usr/local/lib/python2.7/site-packages"
看此错误报告了解更多信息。