'Encountering Fatal Python error when I try to use pip in command prompt
I am a new programmer who is trying to follow this tutorial about pip.
In the tutorial, you are asked to go into command prompt and type 'pip'. You are supposed to get a list of general options and commands. However, when I type pip in my command prompt, I get this instead:
C:\Users\myusername>pip
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'C:\Users\myusername\AppData\Local\Programs\Python\Python310\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'.\\DLLs',
'.\\lib',
'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007590 (most recent call first):
<no Python frame>
(I am using Windows 10 and Python 3.10.4)
I do not know what this means. This is not addressed in the video. This happens whenever I do anything pip-related in the command prompt. I am going to reference this error a lot, so let's call it "The Error."
Here is how I have tried to resolve this problem:
- Running command prompt as administrator. When I type "pip", this returns The Error.
- Downloading get-pip.py, trying to install it via command prompt with
python get-pip.py
. This returns The Error. - Updating my version of Python. I updated the version of Python I have when I encountered this error, making sure that the "Install pip" and "add Python to environment variables" checkboxes were ticked. Updating Python did not fix the problem.
- executing
py -3 -m ensurepip
andpy -m ensurepip --upgrade
in the command prompt. This returns The Error. - Checking that pip is installed in the Scripts folder in Python. It is:
- in command prompt, changing the directory to
C:\Users\myusername\AppData\Local\Programs\Python\Python310\Scripts
and tryingpip --version
andpip install camelcase
from there. This returns The Error. (camelcase is not part of my project, I tried it purely as an example.) - Trying a non-pip related Python command in the command prompt.
python --version
returnsPython 3.10.4
, this works as expected. - Following this Stack Overflow post from someone experiencing the same error.. This is beyond my understanding, and appears to be about Django. I am not doing anything with Django. I just want to use pip. The one piece of information I gleaned from this is this quote from a python developer:
This is not a Python bug, this is a symptom of setting PYTHONHOME and/or PYTHONPATH when they’re not needed. In nearly all cases you don’t need to set either of them;
In the case of PYTHONHOME it’s almost always a mistake to set.
This does not apply to my case, because my PYTHONHOME and PYTHONPATH are not set. The commands unset PYTHONPATH
and unset PYTHONHOME
return 'unset' is not recognized as an internal or external command, operable program or batch file.
I have no idea what's going on and I am confused. All I want to do is go into the command prompt, type pip
and see the list of commands that is supposed to come up. I also want to be able to install python modules using pip. These seem like basic things that should automatically work, yet for some reason I am encountering a problem that is out of my depth.
I am not trying to do anything fancy. I am a basic user who has been learning basic Python for less than a month, with no prior coding experience. How can I overcome this error so I can successfully use pip? Please keep my level of understanding in mind when you answer my question. Thank you!
Solution 1:[1]
The answer was to uninstall and reinstall python, this time telling it to set environment variables. That did the trick.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | WowCool |