尝试使用pip进行安装 刚刚安装了另一个版本的python(3.4) 得到错误
ImportError: cannot import name '_BACKCOMPAT_MAGIC_NUMBER'
答案 0 :(得分:0)
我通过删除旧python版本的tox venv并在安装dev包后重新创建它来解决这个问题。
我做了什么(在Ubuntu 18.04上),从deadsnakes ppa安装旧版本的Python进行测试:
$ 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尝试使用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'
...
删除本地tox virtualenv目录并再次运行:
$ rm -rf .tox/py35
$ tox
...
py35: commands succeeded
答案 1 :(得分:0)
就我而言,我使用的是pipenv,解决方法是删除virtualenv并重新安装依赖项:
$ pipenv --rm
$ pipenv install