I'm trying to import some of my own modules on my mac and I can't figure out how to add the path to my modules. I have tried editing the PYTHONPATH environment variable, (export PYTHONPATH="${PYTHONPATH}:/path/to/modules
) appending the path to sys.path, etc. Nothing seems to work for me. I want the path to be in sys.path permanently so that I don't need to keep putting import sys
then sys.path.append("/path/to/modules")
at the top of every document that I make. Is there a file somewhere that contains the path that I could edit? Or do I need to enter a command into terminal or something? Any help is appreciated.
user8116739
问问题
2909 次
1 回答
0
如果你想“安装”模块,是的,创建一个站点包。如果您只是在本地做某事,为了在您自己的计算机上进行娱乐/教育,请修改 PYTHONPATH。
在 Mac 上,您很可能将bash
其用作 shell。
PYTHONPATH=/path/to/modules:${PYTHONPATH}
export PYTHONPATH
...将在您当前的外壳中执行您想要的操作。要使其永久化(对您而言),请将这两行添加到您.bashrc
的主目录下的本地文件中。
如果您想让这台计算机的所有用户永久使用它......不要在系统范围内编辑/etc/profile
- 那是您真正应该使用软件包正确安装它的时候。
于 2017-09-06T00:32:29.613 回答