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.
Is there a particular reason you’re trying to set these variables? Are you following a guide that suggests it?
I’m actually not using the default python from the repository, but built and installed a newer python manually. Which causes my python is not in the default directory but under $HOME/.local . In such, I need to set up my own PYTHONPATH .
After I unset PYTHONHOME, I still met some further errors which seem relate to Python:
Traceback (most recent call last):
File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator
ModuleNotFoundError: No module named 'CommandNotFound'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code
@zware, I am getting the same error but I don’t have PYTHONHOME or PYTHONPATH set. I am trying to embed python into c++ using pybind11. Here is the simple code:
I installed swift on windows-10. I got similar error when i was trying to run it on command prompt
([vcvarsall.bat] Environment initialized for: ‘x86’).
I got this error
C:\Windows\System32>swift
Python path configuration:
PYTHONHOME = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\lldb.exe'
sys.base_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.base_exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.platlibdir = 'lib'
sys.executable = 'C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\lldb.exe'
sys.prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.path = [
'C:\\Users\\Aarga\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\\DLLs',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\\lib',
'C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin',
]
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 0x000040c0 (most recent call first):
<no Python frame>
It is an old topic, but just in case still helps someone that figured out yet…
If your context is the same as @ jiapei100 and mine, which is building your “own” python from cpython source code repository (forked). In my case for my C programs to run, I have setup this configuration: