0

I have Python (3.9) installed to to my local user account programs folder. When I execute it, I get the following error. A few things that are odd:

  1. In my main Python script, I cannot even do a simple print() first thing, so the problem is directly with Python itself
  2. sys.path has 2 entries that don't exist. I am not sure how they were set to those values, or what set them, but they are wrong as those paths don't exist and a third entry references a zip file, which is probably related to the issue I am having
  3. I inspected all the paths manually and everything is as it should be, and the encodings module does exist

Python only exists in my PATH environment variable once, which is: C:\Users\<username>\AppData\Local\Programs\Python\Launcher\ and that Launcher folder doesn't exist, and I have no idea how it was even set as I intentionally told Python not to add itself to the PATH variable so it would never interfere with other Python installations (which there currently are none).

Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'C:\Users\<username>\AppData\Local\Programs\Python\python.exe'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python39.zip',
    'C:\\Python39\\Lib\\',
    'C:\\Python39\\DLLs\\',
    'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python',
  ]
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 0x000071d4 (most recent call first):
<no Python frame>

If sys.path is incorrect (which it appears as such), how can I manually set this, or fix it? Especially given that my script never gets the opportunity to execute

steveo225
  • 11,394
  • 16
  • 62
  • 114
  • So, it turned out, the installation was missing the `codecs` module, even though the error message said `encodings`. Once I figure that out, there were like 5 modules missing and when I manually added them to the installation folder, Python worked as expected. What I don't like (besides Python reporting the wrong module missing), is that I have seemingly no control over what `sys.path` contains in the event there is an error like this. I set `PYTHONPATH` to force a few additional directories for testing, but why are invalid directories and a zip file in that list? – steveo225 Mar 11 '22 at 13:08

1 Answers1

0

I had a similar problem in which I wanted to use my Ubuntu python installed in /usr/bin but when I typed python, the default python was pointing to Anaconda python installation instead of the python installed in /usr/bin.

I solved that using this: Use the default Python rather than the Anaconda installation when called from the terminal

So in file ~/.bashrc instead of Added by the Anaconda3 4.3.0 installer export PATH="/home/user/anaconda3/bin:$PATH" one would use export PATH="$PATH:/home/user/anaconda3/bin"

AZ123
  • 156
  • 2
  • 11