pip3 --version is throwing an error as of late and I\'m having trouble using pip to install packages to my virtual environment. This is a new issue but I think it could be
I have found a solution to this error, but at present still have not determined the cause for it arising unexpectedly. I suspect it's because I have several installations of python on my computer (different versions as well as downloaded from different locations such as homebrew, anaconda, OSX shipped version, etc...).
Note that the reason for the different installations was not only to install updated versions of python, but also because during my education on python I've taken many classes, often which advise a specific installation method.
When looking into importlib.util there wasn't anything noticeably wrong in the code, so I decided to look into the anaconda installation of python (both python 3.6) and compare importlib.util files.
The top of the importlib.util file throwing the errors looked like this:
"""Utility code for constructing importers, etc."""
import functools
import sys
import types
import warnings
from contextlib import contextmanager
from . import abc
from ._bootstrap import _find_spec
from ._bootstrap import _resolve_name
However, the top of the anaconda version of importlib.util file looked like this:
"""Utility code for constructing importers, etc."""
from . import abc
from ._bootstrap import module_from_spec
from ._bootstrap import _resolve_name
from ._bootstrap import spec_from_loader
from ._bootstrap import _find_spec
from ._bootstrap_external import MAGIC_NUMBER
from ._bootstrap_external import cache_from_source
from ._bootstrap_external import decode_source
from ._bootstrap_external import source_from_cache
from ._bootstrap_external import spec_from_file_location
from contextlib import contextmanager
import functools
import sys
import types
import warnings
Using IntelliJ I could confirm there were no other differences in the two files.
Noting the differences in imports from ._bootstrap_external I copied and pasted the following lines from the anaconda importlib.util file into the usr/bin importlib.util file:
from ._bootstrap_external import MAGIC_NUMBER
from ._bootstrap_external import cache_from_source
from ._bootstrap_external import decode_source
from ._bootstrap_external import source_from_cache
from ._bootstrap_external import spec_from_file_location
from ._bootstrap import spec_from_loader
from ._bootstrap import module_from_spec
After saving, pip3 functionality is restored. I haven't yet determined what caused the change originally but if anyone else has a similar issue I would recommend copying the code from the third block above and inserting it at the top of your importlib.util file.