In your Python interpreter, type the following commands:
>>> import os, sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
Also, you can club all these and use a single line command. Open cmd and enter following command
python -c "import os, sys; print(os.path.dirname(sys.executable))"
Answer from elo80ka on Stack OverflowIn your Python interpreter, type the following commands:
>>> import os, sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
Also, you can club all these and use a single line command. Open cmd and enter following command
python -c "import os, sys; print(os.path.dirname(sys.executable))"
If you have Python in your environment variable then you can use the following command in cmd or powershell:
where python
or for Unix enviroment
which python
command line image :

Python default path
The absolute maze that is installing python and path variables
Could we add Python to system PATH by default? - Ideas - Discussions on Python.org
python - How to add to the PYTHONPATH in Windows, so it finds my modules/packages? - Stack Overflow
Videos
This is most likely due to the path variable. You can see this in a command window by typing
Path
at your prompt.
To update the settings,
- Open the 'System' properties.

- Open Environment Variables

- Highlight the 'Path' Variable and click edit.

- Edit the values for the Python entries, to point to the desired python version.

- OK on all boxes, close any CMD windows open, and open new one. Python command should now reference the correct location.
Solution refers to Windows 10, but is essentially the same on Windows 7 +
I was having the same issue as the older python executable was in my system space (which I have no access to) and the newer version is in the user space.
The work around I thought of was to create a .bat file which will open a CMD window in the user space python version.
new_python.bat:
@set "PATH=C:\Users\USER\AppData\Local\Programs\Python\Python39\;C:\Users\USER\AppData\Local\Programs\Python\Python39\Scripts\;%PATH%"
@cmd /k python --version
Does a decent job for me. Just change the first two lines in the PATH variable to your Python directory and the Python Scripts directory. The CMD which will open using this bat will be ready to run the newer version of python executable.
I've installed python on 1 computer successfully after hours of reading stackoverflow suggestions, youtube videos, documentation etc. And after getting it on there and working I was so frustrated and lost that I had no idea what actions from which source actually worked.
Can someone walk me through this from step 1 why python never works after running the installer and needs all sorts of pointer adjustments in the PATH variable or X other variable like PYTHON PATH to places I can't even manage to keep track of? More specifically, today with a fresh install, what needs to be done to get python to actually install and be detectable by commands.
I'm obviously new, and mostly illiterate to the command prompt so that's part of my difficulty with going through stack overflow where answers 1 through 5 all do something completely different all in command prompt with various opaque arguments, hidden references, implied actions, implied paths etc.
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)
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

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;
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:
- [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
- Click [New] under "System Variable"
- Variable Name: PY_HOME, Variable Value:C:\path\to\python\version

- Click [OK]
- Locate the "Path" System variable and click [Edit]
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
>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.
Do you remember checking the box in the image shown below to add your Python installation to PATH in Windows 10?
Adding Python to PATHWell, I was curious! What if someone accidentally forgot to check that little radio button? What would be the possible recovery steps?
So I spent my evening yesterday uninstalling Python and re-installing to figure out a way to add Python to the PATH post-installation.
If you forget to add Python to the PATH variable, you won't be able to run Python in your command line.
You will get a message saying,
‘python' is not recognized as an internal or external command.
Here are the steps I used to add Python to the PATH variable in Windows 10.
-
Copy the directory to which Python is being installed.
-
Search for System Properties in the Search Bar.
-
Click on the "Environment Variables" button in System Properties.
-
Click on the "Path" variable and then click on "Edit".
-
Now here's the deal. Paste the directory path from Step 1 at the top of the list. You can use the "Move up" button to get it to the top. Now click on "Ok".
I found out that if you paste the path at the end, it still doesn't work. Can someone tell me why?
Anyways, if the steps are not clear to anyone, here is a visual guide containing images of every step, on my blog for achieving the above objective. If you are interested, do take a look.