我有一个存放所有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.

谢谢

其他回答

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

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

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

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

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

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

;D:\Programming\Python34

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

您可以通过命令提示符轻松地设置路径变量。

打开运行并写入cmd 在命令窗口中输入如下命令: 设置路径= % %路径;C: \ python36 按回车。 检查是否写python并输入。您将看到如图所示的python版本。