我有一个存放所有Django应用程序的目录(C:\My_Projects)。我想把这个目录添加到我的PYTHONPATH中,这样我就可以直接调用应用程序。

我试着添加C:\My_Projects\;从Windows GUI到我的Windows路径变量(我的计算机>属性>高级系统设置>环境变量)。但它仍然不读取coltrane模块并生成以下错误:

错误:没有名为coltrane的模块


当前回答

当安装ArcGIS Desktop时,需要为ArcPY设置这个PYTHONPATH变量。

PYTHONPATH=C:\arcgis\bin(您的arcgis主目录)

由于某种原因,当我在Windows 7 32位系统上使用安装程序时,它从未设置过。

其他回答

To augment PYTHONPATH, run regedit and navigate to KEY_LOCAL_MACHINE \SOFTWARE\Python\PythonCore and then select the folder for the python version you wish to use. Inside this is a folder labelled PythonPath, with one entry that specifies the paths where the default install stores modules. Right-click on PythonPath and choose to create a new key. You may want to name the key after the project whose module locations it will specify; this way, you can easily compartmentalize and track your path modifications.

谢谢

import sys
sys.path.append("path/to/Modules")
print sys.path

这将不会持续到重新启动或被翻译到其他文件。然而,如果你不想对你的系统做永久性的修改,这是很好的。

为了确保Python可以根据执行代码的目录找到代码,如果目录中还没有,请在系统环境变量中添加:key PYTHONPATH, value ..

在windows上的Python 3.4中,当我将它添加到PATH环境变量而不是PYTHONPATH时,它工作了。就像如果你在D:\Programming\Python34中安装了Python 3.4,那么在PATH环境变量的末尾添加这个

;D:\Programming\Python34

关闭并重新打开命令提示符并执行“python”。它将打开python shell。这也修正了我Sublime 3的“python不被识别为内部或外部命令”的问题。

你需要添加到你的PYTHONPATH变量而不是Windows PATH变量。

http://docs.python.org/using/windows.html