using pip3: module "importlib._bootstrap" has no attribute "SourceFileLoader"


I have installed pip for python 3.6 on Ubuntu 14. After I run

sudo apt-get install python3-pip

to install pip3, it works very well. However, after installation, when I am trying to run

pip3 install packagename

to install a new package, something strange occurs:

File "/usr/lib/python3/dist-packages/", line 1479, in <module>
 register_loader-type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module "importlib._bootstrap" has no attribute "SourceFileLoader"

It seems that I did nothing wrong, and I really cannot figure out the reason.

Asked By: Arsenal591



Faced the same problem. I think this is because python3.6 and pip3 were installed from different sources.
I suggest using python’s inbuilt facility to install pip i.e

python3 -m ensurepip --upgrade

This should install pip3 and pip3.x where x in python3.x.
Same works for python2 also.

Answered By: azhar22k

I met the same problem, this is the key:

curl -sS | sudo python3
Answered By: Tom Kruise

If you’re getting this error running pip install dotenv, this is because the package is called python-dotenv not dotenv.

This worked for me:

sudo pip install python-dotenv
Answered By: Rod McLaughlin

When updating from python3.4 to python3.6 on ubuntu 14.04. The following solved me:

wget -O - | python3
Answered By: neighbor wang

That’s because you are using an old version of setuptools, check up this issue.

Answered By: Mehrshad Firouzian

I had the same problem on my ubuntu 18.04 with python 3.6. None of the above methods helped, but this one solved the problem:

pip3 uninstall setuptools
Answered By: mishadr

I am facing the same problem, which is solved by downloading the source files of the setuptools and installing the module manually.

The setuptools can be downloaded here:

After downloading, unzip the package first, then cd to the directory and run

python install --user
Answered By: Lutong Zhang

I had the same issue when I tried to install the Slate package in Windows 10, Python 3.7.4 version:

AttributeError: module ‘importlib._bootstrap’ has no attribute ‘SourceFileLoader’

The instruction that generated the error:

C:WINDOWSsystem32>python -m pip install slate

The instruction that worked:

C:WINDOWSsystem32>python -m pip install
Answered By: Mario Aldana

For me the error happened while trying to create a virtual env with python 3.8:

sudo virtualenv venv -ppython3.8

And after trying all the answers here, finally the problem solved by installing the new version of virtualenv (20.0.7):

sudo pip3 install virtualenv
Answered By: Alex Jolig
Traceback (most recent call last):
File "/usr/bin/pipenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/myuser/.local/lib/python3.7/site-packages/", line 
1479, in <module>

Mine looked pretty similar, but for some reason I had a python installation in my home directory .local folder.

I did some of the other answers in this thread to ensure I had good local copy of python, then did:

rm -rf ~/.local
Answered By: user2312718

I had the same problem with my cloud computer. If all above didn’t work for you don’t worry. Here’s how I resolved it:

  1. Download the pip file (pip-version.tar.gz) from:

For cloud, use this

curl --output pip.tar.gz
  1. Extract the content of the file and cd into the directory.
  2. Run the following in the directory
python3 install --user

You should have pip3 working without errors.

Answered By: i Raaj

Tried to install Tensorflow in venv on Windows 10 machine with python 3.8 and got the same issue.

What helped for me was:

pip install setuptools --upgrade
Answered By: fbrand

If you face this issue in anaconda environment, simply upgrade setuptools using the following:

conda install -c conda-forge setuptools
Answered By: M Subramanian

I had faced the same issue on Ubuntu 19.10 and now I upgraded to Ubuntu 20.04 and faced the issue again. This issue is due to broken pip3. So whenever you enter pip3 and hit enter it will show the same error. So instead of using “pip3 uninstall setuptools” use the below code

python3 -m pip uninstall setuptools

It resolved my issue 3rd time

Answered By: Mayank Banga
pip install setuptools --upgrade

This command solved my issue. It fixed my problem.

Answered By: Jeex Box

Just go inside the /usr/lib/python3/dist-packages/, first copy setuptools file somewhere and then delete the setuptools. Everything will be okay for deleting you can use:

sudo rm -r setuptools

for copying

sudo cp -r setuptools /...Desktop/

After that if it gives errors just:

sudo pip3 install setuptools==3.8.1

to download again.

Answered By: Dev Ran

I encountered this error message triggered by a slightly different situation which I’ll mention here for anyone who finds this.

This same error also occurs when installing the distribute Python package (which is currently just a compatibility layer in front of setuptools) in Python 3.6 or newer.

In my specific situation I discovered this as I was using pyzmail which has been somewhat abandoned and depends on distribute.

Collecting distribute
  Downloading (145 kB)
    ERROR: Command errored out with exit status 1:
     command: /var/lang/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ssqyqflj/distribute/'"'"'; __file__='"'"'/tmp/pip-install-ssqyqflj/distribute/'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);'"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-hgbjn0js
         cwd: /tmp/pip-install-ssqyqflj/distribute/
    Complete output (15 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/", line 2, in <module>
        from setuptools.extension import Extension, Library
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/", line 5, in <module>
        from setuptools.dist import _get_unpatched
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/", line 7, in <module>
        from setuptools.command.install import install
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/", line 8, in <module>
        from setuptools.command import install_scripts
      File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/", line 3, in <module>
        from pkg_resources import Distribution, PathMetadata, ensure_directory
      File "/tmp/pip-install-ssqyqflj/distribute/", line 1518, in <module>
        register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
    AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Answered By: gene_wood

I had the same error whatever I asked to pip. I gave a look to this page:

That line is the one that solved my problem:

python3 -m pip install --upgrade pip setuptools wheel
Answered By: FourchetteVerte
pip3 install setuptools --upgrade

This also cured the issue on Python 3.9 running on Windows 10 and even on a custom Docker image.

Answered By: Cruz Jurgen

I was having the same issue while using docker-compose. This exact error can be caused by not being the root user. Running the same commands with sudo fixed it for me. I don’t not have setup-tools installed, and I’m running pip3. My issue was that IntelliJ didn’t have sudo rights, so i had to do it from the terminal.

Answered By: Matthew

Above solutions were not working in my case for Ubuntu 20

If you run the following command:

sudo apt install python3-setuptools

Then you might get the result:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But to actually solve it and re-install setuptools try following commands:

sudo apt download python3-setuptools
sudo dpkg -i python3-setuptools_45.2.0-1_all.deb 

Note: Change the version of the python package that is downloaded

Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.