尝试使用pip安装时,由于刚刚安装了另一个Python版本(3.4),导致出现错误:
ImportError: cannot import name '_BACKCOMPAT_MAGIC_NUMBER'
尝试使用pip安装时,由于刚刚安装了另一个Python版本(3.4),导致出现错误:
ImportError: cannot import name '_BACKCOMPAT_MAGIC_NUMBER'
$ pipenv --rm
$ pipenv install
我通过删除旧版本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
...
$ 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虚拟环境目录,然后重新运行:
$ rm -rf .tox/py35
$ tox
...
py35: commands succeeded