Меню

# How to add Python to Windows PATH

There are few ways in which you can add Python to Windows PATH. In this guide, I’ll share with you two methods that you can use to add Python to Windows path:

• Manual entry of the paths

But why would you want to add Python to Windows path in the first place?

Well, if you try to install a Python package using PIP for example, you may get the following error in the Windows Command Prompt:

‘pip’ is not recognized as an internal or external command, operable program or batch file

To overcome this error, you may apply any of the two methods described below.

Before you proceed, you may choose to uninstall your previous version of Python if needed.

In the Python installation box, just check the box to add Python to PATH as below:

Finish the installation, and you should be good to go.

Alternatively, you may manually add the paths into the Environment variables.

## Method 2: Manually add Python to Windows Path

If you wish to stick with your previous version of Python, you may apply the steps below to manually add Python to Windows path.

Note that I’ll be using Windows 10 to demonstrate the steps, but similar principles would apply for previous versions of Windows.

### Step 1: Navigate to the Windows Environment Variables screen

To navigate to the Windows Environment Variables screen, where you can add/edit your paths, simply right click on the ‘This PC‘ icon. Then, select ‘Properties.’

Next, click on the ‘Advanced system settings

Finally, click on the ‘Environment Variables…

That should take you to the Environment Variables screen, where you can add/edit your paths.

You should then see the following box, which will allow you to add/edit variables:

Before you type any values, you’ll need to locate the relevant Python paths. The paths that you’ll need to get are:

• The Python application path, which is the folder where you originally installed Python; and
• The Python Scripts path. The Scripts folder should be located within the Python application path.

Here is how my Python application path looks like:

And this is how my Python Scripts path looks like:

Now let’s fill the New User Variable box that you saw earlier:

For the Variable name, type ‘Path‘.

For the Variable value, copy the full Python application path, then use semicolon (as highlighted in yellow below), and finally copy the Python Scripts path.

This is how my Variable value looks like:

Put all the values together in the New User Variable box:

Press ‘OK’ and you would then see your new Python Path under the ‘User variables’ section. Don’t forget to press ‘OK’ again so that the changes will get implemented.

That’s it! You just added Python to the Windows Path.

You’ll now be able to install Python packages easily, by opening the Windows Command Prompt and then typing:

pip install package name

For example, to install the pandas package, simply type ‘pip install pandas’ and then press Enter:

Similarly, you may upgrade PIP by typing the following command:

Читайте также:  Plans go out the windows

# Adding Python Path on Windows 7

I’ve been trying to add the Python path to the command line on Windows 7, yet no matter the method I try, nothing seems to work. I’ve used the set command, I’ve tried adding it through the Edit Environment variables prompt etc.

Further more if I run the set command on the command line it lists this

Yet it still doesn’t recognize the Python command.

Reading the documentation, and various other sources hasn’t seemed to help.

Edit: Just to clarify further, I’ve appended the path of the Python executable to PATH in edit environment prompt. Doesn’t seem to work.

1. Hold Win and press Pause .
3. Click Environment Variables.
4. Append ;C:\python27 to the Path variable.
5. Restart Command Prompt.

When setting Environmental Variables in Windows, I have gone wrong on many, many occasions. I thought I should share a few of my past mistakes here hoping that it might help someone. (These apply to all Environmental Variables, not just when setting Python Path)

Watch out for these possible mistakes:

1. Kill and reopen your shell window: Once you make a change to the ENVIRONMENTAL Variables, you have to restart the window you are testing it on.
2. NO SPACES when setting the Variables. Make sure that you are adding the ;C:\Python27 WITHOUT any spaces. (It is common to try C:\SomeOther; C:\Python27 That space (␣) after the semicolon is not okay.)
3. USE A BACKWARD SLASH when spelling out your full path. You will see forward slashes when you try echo $PATH but only backward slashes have worked for me. 4. DO NOT ADD a final backslash. Only C:\Python27 NOT C:\Python27\ # Как добавить в pythonpath в Windows? У меня есть каталог, в котором размещены все мои приложения Django ( C:\My_Projects ). Я хочу добавить этот каталог в мой pythonpath , чтобы я мог напрямую вызывать приложения. Я попытался добавить C:\My_Projects\; в мой Path Ошибка: нет модуля с именем coltrane ## 15 ответов Вы знаете, что очень хорошо сработало для меня в Windows. My Computer > Properties > Advanced System Settings > Environment Variables > Просто добавьте путь как C: \ Python27 (или там, где вы установили python) Затем в системных переменных я создаю новую переменную с именем PythonPath . В этой переменной у меня есть C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path Это лучший способ, который мне помог, которого я не нашел ни в одном из предложенных документов. РЕДАКТИРОВАТЬ: для тех, кто не может его получить, Пожалуйста, добавьте вместе с этим. В противном случае он никогда не будет работать . Windows 7 Профессиональная Я изменил ответ @ mongoose_za, чтобы было легче менять версию Python: 1. [Правый клик] Компьютер> Свойства> Расширенные настройки системы> Переменные среды 2. Нажмите [Создать] в разделе «Системная переменная» 3. Имя переменной: PY_HOME, Значение переменной: C: \ path \ to \ python \ version 4. Нажмите [OK] 5. Найдите системную переменную «Path» и нажмите  Добавьте следующее в существующую переменную: % PY_HOME%;% PY_HOME% \ Lib;% PY_HOME% \ библиотека DLL;% PY_HOME% \ Lib \ Lib-ки; Нажмите [OK], чтобы закрыть все окна. В качестве последней проверки работоспособности откройте командную строку и введите python. Вы должны увидеть Если вам нужно переключаться между версиями, вам нужно только изменить переменную PY_HOME, чтобы она указала на соответствующий каталог. Это немного проще в управлении, если вам нужно установить несколько версий Python. Просто добавьте путь установки (например, C: \ Python27 \ ) в переменную PATH в Системные переменные . Затем закройте и откройте командную строку и введите «python» . Из командной строки Windows: Чтобы установить PYTHONPATH навсегда, добавьте строку в свой autoexec.bat . Кроме того, если вы редактируете системную переменную через Системные свойства, она также будет изменена навсегда. Эти решения работают, но они работают для вашего кода ТОЛЬКО на вашем компьютере. Я бы добавил пару строк в ваш код, которые выглядят так: Это должно решить ваши проблемы Добавление Python и PythonPath в среду Windows: 1. Откройте проводник. 2. Щелкните правой кнопкой мыши «Компьютер» на панели дерева навигации слева. 3. Выберите «Свойства» в нижней части контекстного меню. 4. Выберите «Расширенные настройки системы» . 5. Нажмите «Переменные среды . » на вкладке «Дополнительно» # How to add to the PYTHONPATH in Windows, so it finds my modules/packages? 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. I tried adding C:\My_Projects\; to my Windows 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: Error: No module named coltrane ## 22 Answers 22 You know what has worked for me really well on windows. My Computer > Properties > Advanced System Settings > Environment Variables > Just add the path as C:\Python27 (or wherever you installed python) 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 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 along with it. Else it will never work. Windows 7 Professional I Modified @mongoose_za’s answer to make it easier to change the python version: 1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables 2. Click [New] under «System Variable» 3. Variable Name: PY_HOME, Variable Value:C:\path\to\python\version 4. Click [OK] 5. Locate the «Path» System variable and click  Add the following to the existing variable: %PY_HOME%;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk; Click [OK] to close all of the windows. As a final sanity check open a command prompt and enter python. You should see 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. From Windows command line: 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. 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’. 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: That should take care of your problems Adding Python and PythonPath to the Windows environment: 1. Open Explorer. 2. Right-click ‘Computer’ in the Navigation Tree Panel on the left. 3. Select ‘Properties’ at the bottom of the Context Menu. 4. Select ‘Advanced system settings’ 5. Click ‘Environment Variables. ‘ in the Advanced Tab Under ‘System Variables’: The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows > select Path > Edit > and then add «;C:\Python27\;C:\Python27\Scripts\» You need to add to your PYTHONPATH variable instead of Windows PATH variable. The easiest way to do that successfully, is to run the python installer again (after the first installation) and then: 1. choose Modify. 2. check the optional features which you want and click Next. 3. here we go, in «Advanced Options» step you must see an option saying «Add Python to environment variables». Just check that option and click Install. When the installation is completed, python environment variables are added and you can easily use python everywhere. 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. See here for more information. This won’t persist over reboots or get translated to other files. It is however great if you don’t want to make a permanent modification to your system. 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 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’. 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. The PYTHONPATH environment variable is used by Python to specify a list of directories that modules can be imported from on Windows. When running, you can inspect the sys.path variable to see which directories will be searched when you import something. To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths . To set this variable from PowerShell, use:$env:PYTHONPATH=’list;of;paths’ just before you launch Python.

Setting this variable globally through the Environment Variables settings is not recommended, as it may be used by any version of Python instead of the one that you intend to use. Read more in the Python on Windows FAQ docs.

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.

This question needs a proper answer:

# Just use the standard package site , which was made for this job!

and here is how (plagiating my own answer to my own question on the very same topic):

1. Open a Python prompt and type
1. Create this folder if it does not exist yet:
1. Create a file sitecustomize.py in this folder containing the content of FIND_MY_PACKAGES , either manually or using something like the following code. Of course, you have to change C:\My_Projects to the correct path to your custom import location.

And the next time you start Python, C:\My_Projects is present in your sys.path , without having to touch system-wide settings. Bonus: the above steps work on Linux, too!

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.

I got it worked in Windows 10 by following below steps.

Under environment variables, you should only add it under PATH of «System Variables» and not under «User Variables«. This is a great confusion and eats time if we miss it.

Also, just try to navigate to the path where you got Python installed in your machine and add it to PATH. This just works and no need to add any other thing in my case.I added just below path and it worked.

Most important, close command prompt, re-open and then re-try typing «python» to see the version details. You need to restart command prompt to see the version after setting up the path in environment variables.

After restarting, you should be able to see the python prompt and below info when typing python in command prompt: