Python 3.12 Won't Launch on Windows 11 with Module Encodings Error

I’m trying to install the latest version of Python on Windows 11, but I run into an error that won’t let it launch at all.

For context, I use Python with Anaconda and Spyder. The last time I have programmed in Python was two years ago, so all of my programs were pretty outdated. I uninstalled the old programs from my system first, and then downloaded newest versions of all of them. This was when I realized Anaconda and Spyder won’t launch at all, and would not even give an error message.

After this I tried running python from the windows command line and saw two important error messages:
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
ModuleNotFoundError: No module named ‘encodings’

I’ve tried looking up these error messages but I can’t find a solution that actually works for me. I’ve already uninstalled and reinstalled multiple times, and making sure to select “Add Python to PATH” when I do install it. When I look up these errors I see people working in much different environments than me, e.g. Linux or an IDE, but I can’t even launch my IDEs in the first place since Python won’t run.

Any help would be greatly appreciated- like I mentioned it’s been two years since I last programmed in Python so this is not my forte at all!!

C:\Windows\System32>py
Python path configuration:
  PYTHONHOME = 'C:\edb\languagepack\v2\Python-3.9'
  PYTHONPATH = (not set)
  program name = 'C:\Program Files\Python312\python.exe'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = 'C:\edb\languagepack\v2\Python-3.9\Lib'
  sys._base_executable = 'C:\\Program Files\\Python312\\python.exe'
  sys.base_prefix = 'C:\\edb\\languagepack\\v2\\Python-3.9'
  sys.base_exec_prefix = 'C:\\edb\\languagepack\\v2\\Python-3.9'
  sys.platlibdir = 'DLLs'
  sys.executable = 'C:\\Program Files\\Python312\\python.exe'
  sys.prefix = 'C:\\edb\\languagepack\\v2\\Python-3.9'
  sys.exec_prefix = 'C:\\edb\\languagepack\\v2\\Python-3.9'
  sys.path = [
    'C:\\Program Files\\Python312\\python312.zip',
    'C:\\edb\\languagepack\\v2\\Python-3.9\\DLLs',
    'C:\\edb\\languagepack\\v2\\Python-3.9\\Lib',
    'C:\\Program Files\\Python312',
  ]
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 0x000035cc (most recent call first):
  <no Python frame>

C:\Windows\System32>

I’d rip the whole thing up and start from scratch. You appear to have a Python 3.12 environment trying to load stuff from a 3.9 installation.

Yes- I noticed that and wondered about it. The thing is, I don’t recall ever installing Python 3.9. And I can’t find an actual trace of a 3.9 installation anywhere that I can delete. Do you know where in my files I could check that it’s hiding?

And ripping the whole thing up and starting from scratch, yes, I’d like to do that- but how would I do that other than uninstalling my Python versions, which I’ve already done? How else could I clean it up? Thank you so much for the help.

It seems that you have set environment variables pointing to 3.9 versions of modules. Remove those definitions.

Maybe also clean up the 3.9 files you have installed into \erb.

And for what it’s worth, I’d be surprised if py works for conda based Python because a conda environment needs its activation script ran or half its DLLs will be unfindable.