Python 3.9.1 path variable - python

Good day!
Installed the Python 3.9.1, checked "Add to path", the cmd did not work though.
Added Environment Variable Path, both folder
C:\Users\XXXXX\AppData\Local\Programs\Python\Python39
(file manager opens the path to python.exe just fine)
and script lines:
C:\Users\XXXXX\AppData\Local\Programs\Python\Python39
Still the commands python -version and pip --version do not work from the command line.
Py --version works just fine though.
Anyone might share and idea what might be the reason?

This happens more often than one would think.
When you installed python from python.org and follow the installer, post install, you should check your environment variables, and verify that you have no other python installation (or if you do just name them appropriately).
Often you can find that there is an Environment Variable, that includes a python version on the global Environment Variable Path.
To verify that you are targeting the correct python version put these two directories (replace, user and python version), at the top of your PATH (user's path), and check that there are no conflicts with the rest of the PATH variables.
C:\Users\XXXXX\AppData\Local\Programs\Python\PythonXX
C:\Users\XXXXX\AppData\Local\Programs\Python\PythonXX\Scripts

If you had Python installed in the system before, the new path is added at the end of PATH system variable and when system looks for python.exe it finds first the old version that is available under a different folder.
If you used a command window opened before the new version got installed, it is also possible that system variables did not reload. Close it and use a new one to check.

Related

Python and the PATH

I have two questions about Python as it relates to PATH. First, I wanted to show you how my computer is set up. Right now I have python stored directly on my C drive like so:
The folder "Python" is Python 3.8.3. Now, here are the folders in my PATH environment variable:
My first question is why is that when I type "python" on my terminal (at any path), it launches the python.exe? As of right now, pip install commands and the python command works no matter what path I navigate. I thought that in order for this to happen, you would have to add the folder to where the python.exe was stored to your PATH variable (and the same goes for pip script). To my understanding, python is no where to be found in my environment variable set-up.
My second question is how would I make it to where Python 3.9.1 launches when I type "python" in the command prompt instead of the older version? Likewise, I would like to be able to use this newer version of pip when I type "pip install blabla."
My first question is why is that when I type "python" on my terminal (at any path), it launches the python.exe? As of right now, pip install commands and the python command works no matter what path I navigate. I thought that in order for this to happen, you would have to add the folder to where the python.exe was stored to your PATH variable (and the same goes for pip script). To my understanding, python is no where to be found in my environment variable set-up.
To answer why it works currently, it appears your screenshot is showing your system variables, but it is possible that your Path set in your user variables on your system point to your C:\Python directory. Check your User variables to make sure it isn't set there.
My second question is how would I make it to where Python 3.9.1 launches when I type "python" in the command prompt instead of the older version? Likewise, I would like to be able to use this newer version of pip when I type "pip install blabla."
I would direct you to the python configuration docs. It talks about how to setup your environment to point to the new installation of python. In short, you'd modify your path variable to point to the directory where the new version of python.exe is saved. You also want to add the \Scripts directory that can be found in that directory to your path. That will allow you to use the expected version of pip from the command prompt.

The Python executable is not recognized on Windows 10

I recently installed Python 3.6.3 on my device. When I type python in my cmd window, it gives me this error. I do have the PATH in the environment variables. Path Lists. This should normally fix it, but python is still not recognized.
I had the same problem, due to a stupid decision from Microsoft.
I had another line in my system path variable:
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps
And Windows 10 put a python.exe file there that only redirected me to the Python page of the Microsoft Store:
Since this line was above my true Python path, typing python in the cmd prompt opened the Microsoft Store...
Solution:
Type App execution aliases in the Windows 10 search bar, and then uncheck the aliases for python.exe and python3.exe. More information is here.
The path to the Python executable needs to be in the System PATH variable. Note this is not the User PATH variable.
The OP had Python 3.6.3 installed in C:\Python\Python36-32, however a common default location for installation is in the users AppData\Local\Programs\ folder. This post will assume a Python 3.10 installation in this location. Please adjust as needed for your current Python version and path.
You can confirm the path from the command prompt by checking the Python executable directly from the folder.
cd %LOCALAPPDATA%\Programs\Python\Python310
python --version
This should print the Python interpreter version. For example, Python 3.10.4.
Add the following entries to the System PATH:
%LOCALAPPDATA%\Programs\Python\Python310 for the python executable
%LOCALAPPDATA%\Programs\Python\Python310\Scripts for tools such as pip
After adding the path to the System PATH variable, make sure you close and reopen any command prompts, so they use the updated PATH.
If it is still not working, as mentioned in the previous answers, then simply move up the path, as shown in the screenshot.
You get this error, because the python.exe path has not been added to the System environment variable. To do that, simply:
go to the path C:\Users\%Username%\AppData\Local\Programs\Python\Python37-32 which contains python.exe
copy the path and open System environment variables and in the variable section look for variable called Path. If not, create a new variable with Variable Name as Path and value as the copied path
Once you do that, close the window and simply open cmd. Type python and you should get something like this:
If you are trying to install the new Python version, python-3.9.6, then click the checkbox of Add Python 3.9 to PATH
This happens because the path doesn't exist in environment variables.
To fix this:
Rerun the installer
Choose Modify
In optional feature click "Next"
In advanced option tick the "Add Python to environment variables"
Install
All the answers on Stack Overflow_ about it were obsolete, so I decided to add this. The path variable that needs to be added is,
C:\Users\Username\AppData\Local\Programs\Python\Python36-32
Note that everyone may have a different Username.
If you are working with the command prompt and if you are facing the issue even after adding the Python path to system variable PATH:
Remember to restart the command prompt (cmde.exe).
I too was struggling with this issue, and everything was configured correctly. I installed and setup my system path variables as one would. And everything was fine. Then upon reboot windows would not recognize 'python' as a command as if it were unaware of the path variable. Double checked to confirm everything was still setup correctly (it was).
It only started to work again after I manually browsed to the directory in which python.exe existed, and ran 'python'. After that windows seemed to recognize my path variable and I could call 'python' from where ever need be. Very odd. Figured I'd share in case someone else runs into this.
For Python 3.6, there are actually two path entries. Also, it's best to use the %USERPROFILE% rather than hard coding it.
%USERPROFILE%\AppData\Local\Programs\Python\Python36
%USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts

Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'

I'm installing Python on my Windows 10 laptop, and when I try to run it I get this:
Fatal Python error: Py_Initialize: unable to load the file system
codec ModuleNotFoundError: No module named 'encodings' Current thread
0x0000037c (most recent call first):
I ran into this same issue on Windows 10. Here's how I fixed it:
Open your 'Environment Variables' (Under 'System Properties').
In the window that opens, select the 'Path' row, then click the 'Edit...' button.
There should be two environment variables C:\Python37-32\Scripts\ and C:\Python37-32\ Then click 'OK' (Make sure to check that these path values correspond to the location and version of your Python install.)
Next, in the top portion of the 'Environment Variables' window, look for the PYTHONHOME variable and make sure that it is also set to C:\Python37-32
This issue has been addressed here in this thread. Apparently, running the Python setup as an administrator and/or correctly setting the environment variables solved this issue.
First, don't forget to select "Add Python 3.x to PATH" before you click on Install now and reboot after installation so that the new path is taken into account by Windows.
Second, I had the the same problem with Python 3 on Windows 7 and 64-bit and I got rid of it by deleting PYTHONPATH and PYTHONHOME from Windows 7 system environment variables, because I had a previous installation of Python 2 and those paths were pointing to my the Python 2 directory. I had to simply to delete the PYTHONPATH and PYTHONHOME variables.
I had the same problem (I use a Mac, but I don't think it makes any difference in this problem) and it was coming from the difference between the selected Python interpreter path and the current working directory in spyder.
I use virtual environments in Python to avoid version conflicts of installed modules between various projects (I believe it is a good practice). This leads me to configure the interpreter path in spyder by accessing:
preferences > python interpreter > use the following interpreter
The problem comes when I launch spyder from a different path. I get exactly the same error as Milo's. To solve it I see two options:
change the interpreter path to match the spyder working directory
change the spyder working directory to match the Python interpreter path
I solved this issue by deleting my virtual environment and creating a new one. I believe in my case the error came because the old virtual environment was running on Python 3.6, which I had recently uninstalled and replaced with Python 3.8.
This is probably bad practice in general, but I don't have any real projects where the version matters.
Even I had the same issue when I installed the Python 3.7 beta version, and I resolved it by following these steps:
If you have nay previous version of Python installed and the environment variable and path is set for that version already, just remove the path and environment variable
Run the downloaded Python 3.7 EXE file file as administrator
At the end of installation if it asks the permission for path length just click on that. Now type "python" on the command line and see. It should work.
I am not sure why this question is still here without a solution. I just encountered this and solved by this:
Close all CMD or console emulators.
Go to the system environment settings and clear all old Python path or environment settings. Make sure you check the PATH in both User and System settings as well.
Try again python -V and see if you can run it or not.
If you have removed all Python environment settings, I recommend you to reinstall Python and turn on the Add Python to PATH setting during installation.
Before installing the Python interpreter, check environment and remove the existing PYTHONHOME, and python path under "PATH" of environment. Or change it to the new path to be installed.
If this issue is happening to you in a virtual environment, just delete it and create another. It worked for me.

Pointing bash to a python installed on windows

I am using Windows 10 and have Python installed. The new update brought bash to windows, but when I call python from inside bash, it refers to the Python installation which came with the bash, not to my Python installed on Windows. So, for example, I can't use the modules which I have already installed on Windows and would have to install them separately on the bash installation.
How can I (and can I?) make bash point to my original Windows Python installation? I see that in /usr/bin I have a lot of links with "python" inside their name, but I am unsure which ones to change, and if changing them to Windows directories would even work because of different executable formats.
As of Windows 10 Insider build #14951, you can now invoke Windows executables from within Bash.
You can do this by explicitly calling the absolute path to an executable (e.g. c:\Windows\System32\notepad.exe), or by adding the executable's path to the bash path (if it isn't already), and just calling, for example, notepad.exe.
Note: Be sure to append the .exe to the name of the executable - this is how Linux knows that you're invoking something foreign and routes the invocation request to the registered handler - WSL in this case.
So, in your case, if you've installed Python 2.7 on Windows at C:\, you might invoke it using a command like this from within bash:
$ /mnt/c/Python2.7/bin/python.exe
(or similar - check you have specified each folder/filename case correctly, etc.)
HTH.
I do not have Windows 10 installed, but I use Babun and I had the same problem. As I read aliases work well in Windows 10 shell so simply add alias in your .bashrc pointing to your Python installation directory:
alias python /mnt/c/Python27/python
You have at least four options:
Specify the complete absolute path to the python executable you want to use.
Define an alias in your .bashrc file
Modify the PATH variable in your .bashrc file to include the location of the python version you wish to use.
Create a symlink in a directory which is already in your PATH.

Why wouldn't I want to add Python.exe to my System Path at install time?

I'm reinstalling Python, on Windows 7, and one of the first dialog boxes is the Customize Python screen.
The default setting for "Add Python.exe to Path" is "Entire feature will be unavailable."
I always change this to "Will be installed on local hard drive."
It's not an issue, changing the system environment variables is a snap, but is there any upside to leaving this un-ticked?
If you only have one version of Python installed, it won't matter.
If you have multiple versions installed, then the first one that appears in your system Path will be executed when you use the "python" command. Additionally, it can make older versions inaccessible without extra work. For example, I had a system with Python 2.7 installed and I added 3.2 on top of that and checked the option to to add Python.exe to the path during installation. After doing that, entering both "python" and "python3" on the command line opened up Python 3.2, so I would need to enter the full path to the 2.7 interpreter when I needed to execute 2.x scripts.
One upside I can think of is if you run multiple python versions in windows. So, you have c:\python34 and c:\python27 but both are in the path, you'll get whichever comes first, leading you to a possibly unexpected result.

Categories