ImportError: cannot import name '_BACKCOMPAT_M

2019-02-26 06:53发布

Trying to use pip to install just installed another version of python (3.4) get error

ImportError: cannot import name '_BACKCOMPAT_MAGIC_NUMBER'

1条回答
Root(大扎)
2楼-- · 2019-02-26 07:28

I resolved this for myself by removing the tox venv for the older python version and recreating it after installing the dev package.

What I did (on Ubuntu 18.04), install older version of Python from deadsnakes ppa for testing:

$ sudo add-apt-repository ppa:deadsnakes/ppa
...
 More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Press [ENTER] to continue or Ctrl-c to cancel adding it.
...
$ sudo apt-get install python3.5-dev
...

Reran tox to try to test with Python 3.5:

$ tox
...
ERROR: invocation failed (exit code 1), logfile: ...
ERROR: actionid: py35
msg: installpkg
...
Traceback (most recent call last):
  File ".../.tox/py35/bin/pip", line 7, in <module>
    from pip import main
  File ".../.tox/py35/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File ".../.tox/py35/lib/python3.5/site-packages/pip/utils/__init__.py", line 19, in <module>
    import zipfile
  File "/usr/lib/python3.5/zipfile.py", line 9, in <module>
    import importlib.util
  File ".../.tox/py35/lib/python3.5/importlib/util.py", line 7, in <module>
    from ._bootstrap_external import MAGIC_NUMBER, _BACKCOMPAT_MAGIC_NUMBER
ImportError: cannot import name '_BACKCOMPAT_MAGIC_NUMBER'
...

Delete the local tox virtualenv directory and run again:

$ rm -rf .tox/py35
$ tox
...
  py35: commands succeeded
查看更多
登录 后发表回答