NOTE: There have been several EDITs to the question, as per comments. They are indicated below, and separated by lines. As of now, the only remainin
The ImportError: cannot import name 'open_code' from 'io' (unknown location)
comes from the fact that there are two different versions of Python conflicting with each other. python
still points to the old version 3.7 but PYTHONPATH
got updated to point to the new 3.8 version. As the documentation of PYTHONPATH
states, it becomes prepended to the module search path and hence shadows any builtin modules:
The default search path is installation dependent, but generally begins with
prefix/lib/pythonversion
(seePYTHONHOME
above). It is always appended toPYTHONPATH
.
You can reproduce that behavior by creating two different virtual environments and then start one while having PYTHONPATH
point to the other. In the following I used Miniconda to create two different environments, py37
and py38
, containing a 3.7 and 3.8 installation respectively.
(py37) user@pc:~$ python --version
Python 3.7.6
(py37) user@pc:~$ PYTHONPATH=~/miniconda3/envs/py38/lib/python3.8/ python
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "/home/user/miniconda3/envs/py38/lib/python3.8/io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
Aborted (core dumped)