如何在 Mac 上编辑 PYTHONPATH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15742779/
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 can I edit PYTHONPATH on a Mac?
提问by James
How can I permanently change the PYTHONPATH on a mac? I've tried editing .bash_profile, but when I use print sys.pathin a file it gives a huge list of different URLs than the .bash_profile. In Terminal when I type echo $PYTHONPATHit shows a blank line. I don't want to use sys.path.append('...') because then I have to put that in every file.
如何在 Mac 上永久更改 PYTHONPATH?我试过编辑 .bash_profile,但是当我print sys.path在文件中使用它时,它提供了一个与 .bash_profile 不同的 URL 列表。在终端中,当我输入时,echo $PYTHONPATH它显示一个空行。我不想使用 sys.path.append('...') 因为那样我必须把它放在每个文件中。
采纳答案by 0x90
You can append the path to
$PATHand not to$PYTHONPATH.if you insist to change the
PYTHONPATH, in some context that is prefferable:do this:
export PYTHONPATH=$PYTHONPATH:/Users/username/pymodules- To make sure you are following the convention of what to append to
PYTHONPATHsee What exactly should be set in PYTHONPATH?.
您可以将路径附加到 ,
$PATH而不是附加到$PYTHONPATH。如果您坚持更改
PYTHONPATH, 在某些情况下是可取的:做此:
export PYTHONPATH=$PYTHONPATH:/Users/username/pymodules- 为了确保您遵循附加内容的约定,以
PYTHONPATH查看 PYTHONPATH 中究竟应该设置什么?.

