Trying to use pip to install just installed another version of python (3.4) get error
ImportError: cannot import name \'_BACKCOMPAT_MAGIC_NUMBER\'
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
In my case, I was using pipenv, and the fix was to delete the virtualenv and reinstall the dependencies:
$ pipenv --rm
$ pipenv install