DM71
DM71

Reputation: 77

PyCharm: Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding

Trying to run "helloworld.py" in PyCharm 2020.2 which I thought I'd installed via Anaconda

this error appears in a few threads but the discussions are always about stuff that's a bit beyond a hello world program. I think it might be something to do with this PYTHONPATH thing but I don't understand where this is set (its not in Windows system environment variables), or who set it, or how to fix it.

C:\Users\DrMan\anaconda3\python.exe C:/Users/DrMan/AppData/Local/Programs/Python/Python39/helloworld.py Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH ='C:\Users\DrMan\AppData\Local\Programs\Python\Python39'
program name = 'C:\Users\DrMan\anaconda3\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\Users\DrMan\anaconda3\python.exe'
sys.base_prefix = ''
sys.base_exec_prefix = '' sys.executable = 'C:\Users\DrMan\anaconda3\python.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [ 'C:\Users\DrMan\AppData\Local\Programs\Python\Python39', 'C:\Users\DrMan\anaconda3\python38.zip', 'C:\Users\DrMan\anaconda3', ] 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 0x000098b8 (most recent call first):

Process finished with exit code 1

Upvotes: 3

Views: 10467

Answers (2)

Lars
Lars

Reputation: 1969

In my case it was my root python 3.9 installation (used by my venv), that imported a file from my pycharm project (because my project was in PYTHONPATH).

The easiest way to solve the problem was to rename the file python was trying to import, so python would not find it anymore and fall back to the correct file in (my case) C:\python39.

Upvotes: 2

DM71
DM71

Reputation: 77

OK I found in the settings where I could change the Python Interpreter which I removed and added a link to the directory where i run IDLE and now it works.

If anyone has a good link/reference to understanding all this I would appreciate it. I am a beginner, so haven't really got into worrying about environments and packages and versions but I would like to "grok it" so I don't get into bad habits, like from the ground up how environments, packages and paths and settings are working.

Upvotes: 0

Related Questions