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

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

错误:没有名为coltrane的模块


当前回答

在python中设置路径的简单方法是: >我的电脑>属性>高级系统设置>环境变量> .单击“开始” 第二个Windows >

编辑>然后添加“;C:\Python27\;C:\Python27\Scripts\”

链接:http://docs.python-guide.org/en/latest/starting/install/win/

其他回答

只需将您的安装路径(例如C:\Python27\)附加到系统变量中的path变量。然后关闭并打开你的命令行,输入'python'。

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.

谢谢

在python中设置路径的简单方法是: >我的电脑>属性>高级系统设置>环境变量> .单击“开始” 第二个Windows >

编辑>然后添加“;C:\Python27\;C:\Python27\Scripts\”

链接:http://docs.python-guide.org/en/latest/starting/install/win/

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

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

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

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

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