Msys2 with python 3.8: ImportError: cannot import name 'open_code' from 'io'

前端 未结 1 2049
清酒与你
清酒与你 2020-12-20 21:09

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

相关标签:
1条回答
  • 2020-12-20 21:31

    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 (see PYTHONHOME above). It is always appended to PYTHONPATH.

    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)
    
    0 讨论(0)
提交回复
热议问题