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

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

错误:没有名为coltrane的模块


当前回答

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.

谢谢

其他回答

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.

谢谢

蟒蛇。X路径可以从上面的几个指令中设置。 Python 3默认安装在 Python C:\Users\当地\ AppData \ \程序\ \ Python35-32 \ 所以这个路径必须添加到windows环境中的path变量中。

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

;D:\Programming\Python34

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

这些解决方案可以工作,但它们只适用于您的机器上的代码。我会在代码中添加几行如下所示的代码:

import sys
if "C:\\My_Python_Lib" not in sys.path:
    sys.path.append("C:\\My_Python_Lib")

这样你的问题就解决了

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