Содержание
In this post we are going to show how to set up PythonPath (Python Path) system variable for Windows 10. At first you need to download and install Python in your Windows 10 system. We have installed Python 3.5.0 in our system. When you will try to install Python 3.5.0 in Windows 10, the default location of installation will be C:UsersUser_NameAppDataLocalProgramsPythonPython35-32 as shown below. But you can change the path of the installation using Customize Installation along with that check the «Add Python 3.5 to Path» checkbox. We will be installing Python 3.5.0 in path C:Python35. To add PythonPath in Windows 10, at first you need to click on Action Center on right bottom corner and then click on All Settings. It will open up a Window, in which you need to click on System. In System click on About and scroll down to the bottom and then click on System Info. It will open up a page that contains all details about computer Windows 10 is operating on. On the left you will see few links, in that click on Advanced system settings. It will open up the System Properties in that click on Environment Variables. And then click on new System Variable. In that window add PYTHONPATH as Variable name and C:Python35Lib;C:Python35DLLs; as Variable Value as shown below. Now when you type python in Command line you will get an output as shown below. Please Like and Share CodingDefined.com Blog, if you find it interesting and helpful.
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:
- Via the installation of a recent version of Python
- 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.
Method 1: Install a recent version of Python
You can easily add Python to Windows path by downloading a recent version of Python, and then checking the box to Add Python to PATH during the installation.
Before you proceed, you may choose to uninstall your previous version of Python if needed.
In my case, the latest version of Python that was available to download was version 3.7.2.
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: Get to the Windows Environment Variables screen
To get to the Windows Environment Variables screen, where you can add new 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 new paths.
Click on ‘New…‘ which is located under the User variables box.
You should then see the following box, which will allow you to add new 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, you may type a name, such as ‘Path’ for example.
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 would look like:
C:UsersRonAppDataLocalProgramsPythonPython37-32;C:UsersRonAppDataLocalProgramsPythonPython37-32Scripts
Putting 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:
python -m pip install --upgrade pip
Asked3 years, 11 months agoActive22 days agoViewed 26k times 2
Have set up Python 3.5 and Python 2.7.11 yet both have not been recognized by the command prompt. Also have download pip.py, and the command prompt has not recognized it. Have set the PATH to C:Python34;C:Python34Libsite-packages;C:Python34Scripts;
And have also added the Python 3.5 to PATH through the installation prompts. The computer is a Dell and is a Windows 10 pro computer.
'python' is not recognized as an internal or external command, operable program, or batch file.
'pip' is not recognized as an internal or external command, operable program, or batch file.
|improve this question
2 Answers 2
active oldest votes
I think you have to create a variable called PYTHONPATH, follow the following steps
navigate to My Computer > Properties > Advanced System Settings > Environment Variables >
Then under system variables create a new Variable called PythonPath
.
In this variable include C:Python27Lib;C:Python27DLLs;C:Python27Liblib-tk;C:other-foolder-on-the-path
(no extra spaces)
if someone is there that above is not working, then kindly append to your PATH with the C:Python27
then it should surely work
for complete details here is a link document
|improve this answer
Did you check the path after your modifications? You may need to close and reopen console windows, or even reboot to update your environment variables.
Instead, try py
, which is the Python Launcher. It should be installed in C:Windows which is already in the path. It was an option during install (seee options at bottom of dialog below). Adding Python to the path is also an option, but installing two versions makes only the first one in the path work.
It allows you to pick the version of Python to run:
py # Run default python version...PY_PYTHON env. var can override this. py -3 # Run the latest Python3 found on the system. py -2 # Run the latest Python2 found on the system. py -2.7 # Specifically run Python 2.7. py -2.7-32 # Specifically run 32-bit Python 2.7 on a 64-bit system.
You can also add a #!python3
comment to the top of a script and double-clicking the file in Explorer will use that version of Python.
See: Python Launcher for Windows
|improve this answer
Not the answer you’re looking for? Browse other questions tagged or ask your own question.
lang-pyИспользуемые источники:
- https://www.codingdefined.com/2015/09/how-to-set-up-pythonpath-in-windows-10.html
- https://datatofish.com/add-python-to-windows-path/
- https://stackoverflow.com/questions/35328991/setting-up-python-on-windows-10-pro