如何在windows 7中添加python路径?

时间:2022-06-28 11:20:05

I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my pythonpath so I can call the apps directly.

我有一个包含所有Django应用程序的目录(C:\My_Projects)。我想将这个目录添加到我的pythonpath中,这样我就可以直接调用应用程序了。

I have tried adding C:\My_Projects\; to my Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error:

我尝试过添加C:\My_Projects\;到Windows GUI中的Path变量(我的计算机>属性>高级系统设置>环境变量)。但是它仍然没有读取coltrane模块并产生这个错误:

Error: No module named coltrane

错误:没有名为coltrane的模块

16 个解决方案

#1


324  

You know what has worked for me really well on windows.

你知道什么在windows上对我很管用。

My Computer > Properties > Advanced System Settings > Environment Variables >

我的计算机>属性>高级系统设置>环境变量>

Just add the path as C:\Python27 (or wherever you installed python)

只需将路径添加为C:\Python27(或在您安装python的任何地方)

OR

Then under system variables I create a new Variable called PythonPath. In this variable I have C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path

然后在系统变量下,我创建一个名为PythonPath的新变量。在这个变量中,我有C:\Python27\Lib;C:\Python27\ Lib\ Lib -tk;C:\ others -folders on- on- path

如何在windows 7中添加python路径?

This is the best way that has worked for me which I hadn't found in any of the docs offered.

这对我来说是最好的方法,我在任何一个医生提供的资料中都找不到。

EDIT: For those who are not able to get it, Please add

编辑:如果您无法获得,请添加

C:\Python27;

C:\ Python27;

along with it. Else it will never work.

随着它。否则它永远不会起作用。

#2


93  

Windows 7 Professional I Modified @mongoose_za's answer to make it easier to change the python version:

我修改了@mongoose_za的答案,使修改python版本更容易:

  1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
  2. [右击]计算机>属性>高级系统设置>环境变量
  3. Click [New] under "System Variable"
  4. 在“系统变量”下点击[New]
  5. Variable Name: PY_HOME, Variable Value:C:\path\to\python\version 如何在windows 7中添加python路径?
  6. 变量名:PY_HOME,变量值:C:\路径\到\python\版本
  7. Click [OK]
  8. 单击[确定]
  9. Locate the "Path" System variable and click [Edit]
  10. 定位“路径”系统变量并点击【编辑】
  11. Add the following to the existing variable:

    在现有变量中增加以下内容:

    %PY_HOME%;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk; 如何在windows 7中添加python路径?

    % PY_HOME %,% PY_HOME % \ Lib;% PY_HOME % \ dll;% PY_HOME % \ Lib \ lib-tk;

  12. Click [OK] to close all of the windows.

    单击[OK]关闭所有窗口。

As a final sanity check open a command prompt and enter python. You should see

作为最后的完整性检查,打开命令提示符并输入python。您应该看到

>python [whatever version you are using]

If you need to switch between versions, you only need to modify the PY_HOME variable to point to the proper directory. This is bit easier to manage if you need multiple python versions installed.

如果需要在不同版本之间切换,只需修改PY_HOME变量以指向适当的目录。如果需要安装多个python版本,这将更容易管理。

#3


63  

Just append your installation path (ex. C:\Python27\) to the PATH variable in System variables. Then close and open your command line and type 'python'.

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

#4


48  

From Windows command line:

从Windows命令行:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

To set the PYTHONPATH permanently, add the line to your autoexec.bat. Alternatively, if you edit the system variable through the System Properties, it will also be changed permanently.

要永久性地设置PYTHONPATH,将行添加到您的autoexecl .bat中。或者,如果您通过系统属性编辑系统变量,它也将被永久地修改。

#5


45  

These solutions work, but they work for your code ONLY on your machine. I would add a couple of lines to your code that look like this:

这些解决方案有效,但是它们只适用于您的机器上的代码。我将在代码中添加几行代码如下所示:

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

That should take care of your problems

那应该能解决你的问题

#6


29  

Adding Python and PythonPath to the Windows environment:

在Windows环境中添加Python和PythonPath:

  1. Open Explorer.
  2. 打开浏览器。
  3. Right-click 'Computer' in the Navigation Tree Panel on the left.
  4. 在左边的导航树面板中右键单击“Computer”。
  5. Select 'Properties' at the bottom of the Context Menu.
  6. 在上下文菜单的底部选择“Properties”。
  7. Select 'Advanced system settings'
  8. 选择“高级系统设置”
  9. Click 'Environment Variables...' in the Advanced Tab
  10. 点击“环境变量……在高级标签中
  11. Under 'System Variables':

    在“系统变量”:

    1. Add

      添加

      • PY_HOME

        PY_HOME

        C:\Python27
        
      • PYTHONPATH

        PYTHONPATH环境

        %PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;C:\another-library
        
    2. Append

      附加

      • path

        路径

        %PY_HOME%;%PY_HOME%\Scripts\
        

#7


16  

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

在python中设置路径的更简单的方法是:单击启动>我的计算机>属性>高级系统设置>环境变量>秒windows >

如何在windows 7中添加python路径?

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

选择Path >编辑>,然后添加“;C:\Python27\;C:\Python27\Scripts\脚本”

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

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

#8


12  

You need to add to your PYTHONPATH variable instead of Windows PATH variable.

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

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

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

#9


11  

You can also add a .pth file containing the desired directory in either your c:\PythonX.X folder, or your \site-packages folder, which tends to be my preferred method when I'm developing a Python package.

您还可以在c:\PythonX中添加一个包含所需目录的.pth文件。X文件夹,或您的\站点包文件夹,这是我在开发Python包时首选的方法。

See here for more information.

更多信息请看这里。

#10


4  

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.

要增强PYTHONPATH,运行regedit并导航到KEY_LOCAL_MACHINE \Python\Python \PythonCore软件,然后为您希望使用的Python版本选择文件夹。这是一个标记为PythonPath的文件夹,其中一个条目指定默认安装存储模块的路径。右键单击PythonPath并选择创建一个新键。您可能想要在它将指定的模块位置的项目之后命名密钥;这样,您就可以轻松地划分和跟踪您的路径修改。

thanks

谢谢

#11


3  

In Python 3.4 on windows it worked when I added it to PATH enviroment variable instead of PYTHONPATH. Like if you have installed Python 3.4 in D:\Programming\Python34 then add this at the end of your PATH environment variable

在Python 3.4中,当我将它添加到PATH环境变量而不是PYTHONPATH时,它就可以工作了。就像在D中安装了Python 3.4:\编程\Python34,然后在PATH环境变量的末尾添加这个。

;D:\Programming\Python34

Close and reopen command prompt and execute 'python'. It will open the python shell. This also fixed my Sublime 3 issue of 'python is not recognized as an internal or external command'.

关闭并重新打开命令提示符并执行“python”。它将打开python shell。这也解决了我关于“python不被视为内部或外部命令”的崇高问题。

#12


3  

The python 2.X paths can be set from few of the above instructions. Python 3 by default will be installed in C:\Users\\AppData\Local\Programs\Python\Python35-32\ So this path has to be added to Path variable in windows environment.

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

#13


2  

For anyone trying to achieve this with Python 3.3+, the Windows installer now includes an option to add python.exe to the system search path. Read more in the docs.

对于任何试图使用Python 3.3+实现这一点的人来说,Windows安装程序现在包含了添加Python的选项。执行到系统搜索路径。阅读更多的文档。

#14


2  

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

You have to do this only once.

你只需要做一次。

#15


1  

This PYTHONPATH variable needs to be set for ArcPY when ArcGIS Desktop is installed.

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

PYTHONPATH=C:\arcgis\bin (your ArcGIS home bin)

PYTHONPATH=C:\arcgis\bin(您的arcgis home bin)

For some reason it never was set when I used the installer on a Windows 7 32-bit system.

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

#16


0  

Maybe a little late, but this is how you add the path to the Windows Environment Variables.

可能有点晚了,但这是向Windows环境变量添加路径的方法。

  1. Go to the Environment Variables tab, you do this by pressing Windows key + Pausa inter.

    转到“环境变量”选项卡,按下Windows key + Pausa inter。

  2. Go to Advanced System Settings.

    进入高级系统设置。

  3. Click on Environment Variables.

    点击环境变量。

  4. On the lower window search for the 'Path' value.

    在下面的窗口中搜索“路径”值。

  5. Select it

    选择它

  6. Click on Edit

    点击编辑

  7. In the end of the line add your instalation folder and the route to 'Scripts' folder.

    在最后一行添加您的instalation文件夹和到“Scripts”文件夹的路径。

  8. Click ok, aceptar etc.

    单击ok,aceptar等等。

You're done, enter cmd and write python from any location of your drive, it should enter the Python program.

完成之后,输入cmd并从驱动器的任何位置编写python,它应该进入python程序。

Example with my pc (I have Python34)

例如我的pc(我有Python34)

EXISTING_LINES;C:\Python34;C:\Python34\Scripts\

Hope it helps.

希望它可以帮助。

Greetings from Bogotá

波哥大的问候

#1


324  

You know what has worked for me really well on windows.

你知道什么在windows上对我很管用。

My Computer > Properties > Advanced System Settings > Environment Variables >

我的计算机>属性>高级系统设置>环境变量>

Just add the path as C:\Python27 (or wherever you installed python)

只需将路径添加为C:\Python27(或在您安装python的任何地方)

OR

Then under system variables I create a new Variable called PythonPath. In this variable I have C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path

然后在系统变量下,我创建一个名为PythonPath的新变量。在这个变量中,我有C:\Python27\Lib;C:\Python27\ Lib\ Lib -tk;C:\ others -folders on- on- path

如何在windows 7中添加python路径?

This is the best way that has worked for me which I hadn't found in any of the docs offered.

这对我来说是最好的方法,我在任何一个医生提供的资料中都找不到。

EDIT: For those who are not able to get it, Please add

编辑:如果您无法获得,请添加

C:\Python27;

C:\ Python27;

along with it. Else it will never work.

随着它。否则它永远不会起作用。

#2


93  

Windows 7 Professional I Modified @mongoose_za's answer to make it easier to change the python version:

我修改了@mongoose_za的答案,使修改python版本更容易:

  1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
  2. [右击]计算机>属性>高级系统设置>环境变量
  3. Click [New] under "System Variable"
  4. 在“系统变量”下点击[New]
  5. Variable Name: PY_HOME, Variable Value:C:\path\to\python\version 如何在windows 7中添加python路径?
  6. 变量名:PY_HOME,变量值:C:\路径\到\python\版本
  7. Click [OK]
  8. 单击[确定]
  9. Locate the "Path" System variable and click [Edit]
  10. 定位“路径”系统变量并点击【编辑】
  11. Add the following to the existing variable:

    在现有变量中增加以下内容:

    %PY_HOME%;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk; 如何在windows 7中添加python路径?

    % PY_HOME %,% PY_HOME % \ Lib;% PY_HOME % \ dll;% PY_HOME % \ Lib \ lib-tk;

  12. Click [OK] to close all of the windows.

    单击[OK]关闭所有窗口。

As a final sanity check open a command prompt and enter python. You should see

作为最后的完整性检查,打开命令提示符并输入python。您应该看到

>python [whatever version you are using]

If you need to switch between versions, you only need to modify the PY_HOME variable to point to the proper directory. This is bit easier to manage if you need multiple python versions installed.

如果需要在不同版本之间切换,只需修改PY_HOME变量以指向适当的目录。如果需要安装多个python版本,这将更容易管理。

#3


63  

Just append your installation path (ex. C:\Python27\) to the PATH variable in System variables. Then close and open your command line and type 'python'.

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

#4


48  

From Windows command line:

从Windows命令行:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

To set the PYTHONPATH permanently, add the line to your autoexec.bat. Alternatively, if you edit the system variable through the System Properties, it will also be changed permanently.

要永久性地设置PYTHONPATH,将行添加到您的autoexecl .bat中。或者,如果您通过系统属性编辑系统变量,它也将被永久地修改。

#5


45  

These solutions work, but they work for your code ONLY on your machine. I would add a couple of lines to your code that look like this:

这些解决方案有效,但是它们只适用于您的机器上的代码。我将在代码中添加几行代码如下所示:

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

That should take care of your problems

那应该能解决你的问题

#6


29  

Adding Python and PythonPath to the Windows environment:

在Windows环境中添加Python和PythonPath:

  1. Open Explorer.
  2. 打开浏览器。
  3. Right-click 'Computer' in the Navigation Tree Panel on the left.
  4. 在左边的导航树面板中右键单击“Computer”。
  5. Select 'Properties' at the bottom of the Context Menu.
  6. 在上下文菜单的底部选择“Properties”。
  7. Select 'Advanced system settings'
  8. 选择“高级系统设置”
  9. Click 'Environment Variables...' in the Advanced Tab
  10. 点击“环境变量……在高级标签中
  11. Under 'System Variables':

    在“系统变量”:

    1. Add

      添加

      • PY_HOME

        PY_HOME

        C:\Python27
        
      • PYTHONPATH

        PYTHONPATH环境

        %PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;C:\another-library
        
    2. Append

      附加

      • path

        路径

        %PY_HOME%;%PY_HOME%\Scripts\
        

#7


16  

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

在python中设置路径的更简单的方法是:单击启动>我的计算机>属性>高级系统设置>环境变量>秒windows >

如何在windows 7中添加python路径?

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

选择Path >编辑>,然后添加“;C:\Python27\;C:\Python27\Scripts\脚本”

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

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

#8


12  

You need to add to your PYTHONPATH variable instead of Windows PATH variable.

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

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

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

#9


11  

You can also add a .pth file containing the desired directory in either your c:\PythonX.X folder, or your \site-packages folder, which tends to be my preferred method when I'm developing a Python package.

您还可以在c:\PythonX中添加一个包含所需目录的.pth文件。X文件夹,或您的\站点包文件夹,这是我在开发Python包时首选的方法。

See here for more information.

更多信息请看这里。

#10


4  

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.

要增强PYTHONPATH,运行regedit并导航到KEY_LOCAL_MACHINE \Python\Python \PythonCore软件,然后为您希望使用的Python版本选择文件夹。这是一个标记为PythonPath的文件夹,其中一个条目指定默认安装存储模块的路径。右键单击PythonPath并选择创建一个新键。您可能想要在它将指定的模块位置的项目之后命名密钥;这样,您就可以轻松地划分和跟踪您的路径修改。

thanks

谢谢

#11


3  

In Python 3.4 on windows it worked when I added it to PATH enviroment variable instead of PYTHONPATH. Like if you have installed Python 3.4 in D:\Programming\Python34 then add this at the end of your PATH environment variable

在Python 3.4中,当我将它添加到PATH环境变量而不是PYTHONPATH时,它就可以工作了。就像在D中安装了Python 3.4:\编程\Python34,然后在PATH环境变量的末尾添加这个。

;D:\Programming\Python34

Close and reopen command prompt and execute 'python'. It will open the python shell. This also fixed my Sublime 3 issue of 'python is not recognized as an internal or external command'.

关闭并重新打开命令提示符并执行“python”。它将打开python shell。这也解决了我关于“python不被视为内部或外部命令”的崇高问题。

#12


3  

The python 2.X paths can be set from few of the above instructions. Python 3 by default will be installed in C:\Users\\AppData\Local\Programs\Python\Python35-32\ So this path has to be added to Path variable in windows environment.

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

#13


2  

For anyone trying to achieve this with Python 3.3+, the Windows installer now includes an option to add python.exe to the system search path. Read more in the docs.

对于任何试图使用Python 3.3+实现这一点的人来说,Windows安装程序现在包含了添加Python的选项。执行到系统搜索路径。阅读更多的文档。

#14


2  

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

You have to do this only once.

你只需要做一次。

#15


1  

This PYTHONPATH variable needs to be set for ArcPY when ArcGIS Desktop is installed.

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

PYTHONPATH=C:\arcgis\bin (your ArcGIS home bin)

PYTHONPATH=C:\arcgis\bin(您的arcgis home bin)

For some reason it never was set when I used the installer on a Windows 7 32-bit system.

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

#16


0  

Maybe a little late, but this is how you add the path to the Windows Environment Variables.

可能有点晚了,但这是向Windows环境变量添加路径的方法。

  1. Go to the Environment Variables tab, you do this by pressing Windows key + Pausa inter.

    转到“环境变量”选项卡,按下Windows key + Pausa inter。

  2. Go to Advanced System Settings.

    进入高级系统设置。

  3. Click on Environment Variables.

    点击环境变量。

  4. On the lower window search for the 'Path' value.

    在下面的窗口中搜索“路径”值。

  5. Select it

    选择它

  6. Click on Edit

    点击编辑

  7. In the end of the line add your instalation folder and the route to 'Scripts' folder.

    在最后一行添加您的instalation文件夹和到“Scripts”文件夹的路径。

  8. Click ok, aceptar etc.

    单击ok,aceptar等等。

You're done, enter cmd and write python from any location of your drive, it should enter the Python program.

完成之后,输入cmd并从驱动器的任何位置编写python,它应该进入python程序。

Example with my pc (I have Python34)

例如我的pc(我有Python34)

EXISTING_LINES;C:\Python34;C:\Python34\Scripts\

Hope it helps.

希望它可以帮助。

Greetings from Bogotá

波哥大的问候