pip3 error - '_NamespacePath' object has no attribute 'sort' - python

I tried to install a package through pip3, and I got this error. Every pip/pip3 command that I run gives me this error-
alexg#hitbox:~$ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
#_call_aside
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
I have tried running pip3 install --upgrade pip setuptools according to some answers, but every pip command gives me the error. I'm stuck and can't do anything.
What could have caused it, and how can this be fixed?
I'm on Ubuntu 16.04 with Python 3.5.2

I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027
More specifically, I edited line #2121~2122 of this file: "sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py"
#orig_path.sort(key=position_in_sys_path)
#module.__path__[:] = [_normalize_cached(p) for p in orig_path]
orig_path_t = list(orig_path)
orig_path_t.sort(key=position_in_sys_path)
module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

Upgrading setuptools worked for me:
pip3 install --upgrade setuptools

This may sound weird, because I had this issue and I had tried everything mentioned in SO and GitHub issues. But then I installed pip with easyinstall and pip command is working. Maybe now there are 2 pip packages now. But error is gone.
easy_install pip

I'm using virtualenv and upgrading setuptools didn't work for me. What did work was this workaround:
pip uninstall setuptools -y && pip install setuptools

Yet another answer, but following is the one which eventually fixed the issue for me. Since pip was compromised I was unable to use it for upgrading itself or setuptools and also using easy_install was bringing up the same issue. So I tried to install pip using Python.
The answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install --upgrade setuptools

try -
pip install -U pip
pip install -U setuptools
if editing __init__.py doesnt help.

I tried most of the above suggested solutions but nothing worked as pip3 was totally non-functional, then I found this:
https://deeptalk.lambdalabs.com/t/trying-to-uninstall-tensorflow-or-matplotlib-pip-package-throws-attributeerror--namespacepath-object-has-no-attribute-sort/310
I think this is probably the issue with most of us. I tried the suggested solution and pip3 is working again.
For me the matplotlib was not present in dist-packages but instead it was in site-packages, so the command that worked for me was:
sudo rm ~/.local/lib/python3.5/site-packages/matplotlib-3.0.3-py3.5-nspkg.pth
ofcourse you need to change the above path based on your version and location of matplotlib.

This probably means that your dependencies got messed up.
Try to uninstall pip3 from scratch and it should work.
In case it doesn't work, delete your pip installation. In your case:
rm -r /home/alexg/.local/lib/python3.5/site-packages/pip/
And to be sure next time, best to work with virtual environments :)

Try :
sudo easy_install pip
and then
sudo easy_install setuptools
It probably happends because of messed-up dependencies.

I had the same problem using poetry.
Running
poetry run pip install --upgrade pip setuptools
instead of
pip install --upgrade pip setuptools
fixed the issue.

I had this same problem, and was unable to run any command with pip3 (including any commands like pip3 install --upgrade pip setuptools).
Only fix I've found was to completely uninstall and re-install python 3 (sudo apt-get remove python3, sudo apt-get install python3, sudo apt install python3-pip) and now pip3 is working properly again.

After trying all kinds of methods, such as reinstall pip, setuptools, and still can't fix the problem.
I follow the instruction of https://github.com/pypa/pip/issues/4216#issuecomment-286348680 and only with an external warning.
After that, I use pip to uninstall matplotlib.
Finally, all things seem okay.

I had this problem consistently (and used the workaround below to use pip in the python3 interpreter). To my surprise, after uninstalling all versions of numpy and reinstalling the latest one, pip began working again. I can't say for sure what happened, but it might be something to try if everything else has failed.
The workaround (pieced together from several sources I don't recall) is
start python3
import pip twice (getting an error the first time)
use pip.main within the interpreter
Here is a transcript:
>>> import pip
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py",
__import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'
During handling of the above exception, another exception occurred
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13,
from pip.exceptions import InstallationError, CommandError, Pi
File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6,
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
vendored("pkg_resources")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
__import__(modulename, globals(), locals(), level=0)
.
etc
.
AttributeError: '_NamespacePath' object has no attribute 'sort'
>>> import pip
>>> pkgs = ['asciiplotlib']
>>> pip.main(['install'] + pkgs + ['--upgrade'])
Collecting asciiplotlib
Using cached https://files.pythonhosted.org/packages/15/c5/46a2d
Installing collected packages: asciiplotlib
Successfully installed asciiplotlib-0.1.8

I fixed this with follows:
$curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
For python2:
$python get-pip.py
For python3:
$python3 get-pip.py
Now it works for me.

None of the other posted answered worked for me, but running the follow command solved t:
sudo apt-get purge --auto-remove python3-pkg-resources python3-setuptools

This is for windows users, who installed WinPython
We couldn't even run pip command. Uninstall and install of Anaconda 3
We faced similar error. Finally we removed folder "Python" which is inside C:\Users\you\AppData\Roaming\ and removed folder "conda" & "packages" which is inside C:\Users\you\AppData\Roaming\conda.
Then it worked.

Related

Update python libraries with pip went wrong [duplicate]

So recently I had to reinstall python due to corrupt executable. This made one of our python scripts bomb with the following error:
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
The line of code that caused it to bomb was:
from apiclient.discovery import build
I tried pip uninstalling and pip upgrading the google-api-python-client but I cant seem to find any information on this particular error.
For what it is worth - I am trying to pull google analytics info down via API call.
here is an output of the command prompt error
File "C:\Analytics\Puritan_GoogleAnalytics\Google_Conversions\mcfTest.py", line 1, in <module>
from apiclient.discovery import build
File "C:\ProgramData\Anaconda3\lib\site-packages\apiclient\__init__.py", line 3, in <module>
from googleapiclient import channel, discovery, errors, http, mimeparse, model
File "C:\ProgramData\Anaconda3\lib\site-packages\googleapiclient\discovery.py", line 57, in <module>
from googleapiclient import _auth, mimeparse
File "C:\ProgramData\Anaconda3\lib\site-packages\googleapiclient\_auth.py", line 34, in <module>
import oauth2client.client
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\client.py", line 45, in <module>
from oauth2client import crypt
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\crypt.py", line 45, in <module>
from oauth2client import _openssl_crypt
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\_openssl_crypt.py", line 16, in <module>
from OpenSSL import crypto
File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\crypto.py", line 1517, in <module>
class X509StoreFlags(object):
File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\crypto.py", line 1537, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
Edit the crypto.py file mentioned in the stacktrace and remove the offending line by commenting it out with a #
Then upgrade latest version of PyOpenSSL.
pip install pip --upgrade
pip install pyopenssl --upgrade
Now you can re-add the commented line again and it should be working
As all the above failed for me i used the trick here: https://askubuntu.com/a/1433089/497392
sudo apt remove python3-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
And then after a reboot:
pip install pyopenssl --upgrade
pip3 install pyOpenSSL --upgrade
solved all my issues.
on my ubuntu "20.04.5" I manage solving the error:
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK\r
by re-installing the following packages:
apt-get --reinstall install python-apt
apt-get --reinstall install apt-transport-https
apt-get install build-essential libssl-dev libffi-dev python-dev
I do not use pip as I received this error message using ansible playbook and wasn't able to reach the servers anymore.
Hope it helps somebody on day.
For me, earlier answers can't help me as I meet this problem for all pip commands, even pip3 -V. But I solved it by:
wget https://files.pythonhosted.org/packages/00/3f/ea5cfb789dddb327e6d2cf9377c36d9d8607af85530af0e7001165587ae7/pyOpenSSL-22.1.0-py3-none-any.whl (get url from https://pypi.org/project/pyOpenSSL/#files if you need the latest version)
python3 -m easy_install pyOpenSSL-22.1.0-py3-none-any.whl
Thanks https://askubuntu.com/a/1429674
I also encountered this error while installing Flask and firebase-admin on Ubuntu 20.04. The following commands solved my problem.
First I removed OpenSSL using this command.
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
sudo pip3 install pyopenssl
sudo pip3 install pyopenssl --upgrade
Below commands worked for me...
sudo pip3 install pyopenssl
sudo pip3 install pyopenssl --upgrade
I stumbled into this problem this morning trying to install weasyprint after a system update and restart. Commenting out the line containing
X509_V_FLAG_CB_ISSUER_CHECK
in /usr/lib/python3/dist-packages/OpenSSL/crypto.py resulted in a further error
AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
None of the suggested fixes would work for me.
sudo apt remove python3-pip followed by sudo apt install python3-pip
sudo pip install pyopenssl --upgrade
sudo python3 -m easy_install pyOpenSSL-22.0.0-py2.py3-none-any.whl
sudo pip install --force-reinstall "cryptography==38.0.4"
I found this module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' but it didn't add to anything I already knew. I found this AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms' but it comes with WARNINGS for people running on desktops and it causing significant system wide issues.
I tried upgrading OpenSSL via easy_install but the wheel could not be found and there was a depreciation warning. Eventually I came back to the comment by #Alexandr who said just remove OpenSSL with rm.
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
From here I attempted to reinstall OpenSSL but found it was already statisfied. Maybe an older package was blocking and this was the root of the problem?
sudo pip install pyopenssl
Requirement already satisfied: pyopenssl in /usr/lib/python3/dist-packages (19.0.0)
I then upgraded pip and was able to install WeasyPrint which I hope confirms I have solved this issue.
pip install pip --upgrade
Successfully installed pip-22.3.1
pip install weasyprint
Successfully installed Pyphen-0.13.2 ... weasyprint-57.2 zopfli-0.2.2
sudo apt remove python3-openssl
If you have pip completely broken, as #sgdesmet propose in a comment, the only option to resolve this issue is
"Edit the crypto.py file and remove the offending line by commenting it out with a #"
No other solutions work with me.
If pip / pip3 is completely broken and nothing of the other option work (as described by #DarkSkull), then the line in the crypto.py file that's causing the issue has to be deleted or commented out.
Here's an automated way of doing it:
python_openssl_crypto_file="/usr/lib/python3/dist-packages/OpenSSL/crypto.py"
search_term="CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK"
cb_issuer_check_line_number="$(awk "/$search_term/ {print FNR}" $python_openssl_crypto_file)"
sed -i "${cb_issuer_check_line_number}s/.*/ # $search_term/" $python_openssl_crypto_file
I've tried upgrading pip and installing another version of pyOpenSSL from whl file, but that didn't work. The only thing that helped is removing the entire folder with OpenSSL module like that rm -rf ...python-3.8.10/lib/python3.8/site-packages/OpenSSL and then doing all the thing you need.
Thanks to the answers above I was able to solve the same problem. I use pipenv to manage my environment. The issue arose after upgrading my cryptography module.
The fix (for me):
pipenv update pyOpenSSL

Pip command line "ImportError: No Module Named Typing"

Running the following command gives me the following error:
pip install pygame
Error Stack:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
Running this line in a Mac terminal fixed it for me:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install --upgrade pip
I had the same issue. I also first tried the pip3 install pygame which was previously mentioned, before running this line. You may have to do that first. For the individual who said to try
pip install typing
that line of code will simply produce the same error. To fix it, you have to use to the aforementioned command(s).
I also ran into the same problem, because I made the foolish mistake of upgrading pip as suggested by Python.
I fixed this by downloading get_pip.py for python3.4 at https://bootstrap.pypa.io/pip/3.4/get-pip.py and running it:
python get_pip.py
It will automatically download the latest compatible version of pip (19.1.1 in this case).
Try to:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
Do the following:
sudo apt update
sudo apt-get upgrade
If there is a problem, do:
sudo apt --fix-broken install
sudo apt-get upgrade
If there is still a problem, remove and recreate your venv. And Reinstall your requirements:
rm -rf venv
python3.9 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
I encountered the same error on Ubuntu 20.04 when using python3.9, I tried to run sudo apt update && sudo apt upgrade.
The output advised me to run sudo apt --fix-broken install, which had solved my problem and python3.9 is running fine now.
I have also met this problem. Any command that starts with pip have the same error, ImportError: No module named 'typing'.
Finally, python -m pip install typing solved it.
I had this error using pip because my Ubuntu installation with Python 2.7 and Python 3.5 were crossed using the versions and pip.
My solution was to uninstall Python 2.7 and pip 2.7. I also uninstalled Python 3.5 and pip 3.
I then installed Python 3.7 using these directions: Installing the latest Python 3.7 on Ubuntu 16.04 and 18.04
I'm not sure if uninstalling 3.5 and adding 3.7 is necessary. You may just be able to remove 2.7 and be good, but this is what worked for me.
Try this one:
pip3 install pygame
It looks like you are importing from the package 'typing' but you do not have it installed. Try installing the package:
pip install typing

Can't able to install any python packages [duplicate]

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/pkg_resources.py", 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.
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
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.
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
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
I had the same error whatever I asked to pip. I gave a look to this page: https://packaging.python.org/tutorials/installing-packages/
That line is the one that solved my problem:
python3 -m pip install --upgrade pip setuptools wheel
pip install setuptools --upgrade
This command solved my issue. It fixed my problem.
When updating from python3.4 to python3.6 on ubuntu 14.04. The following solved me:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3
If you face this issue in anaconda environment, simply upgrade setuptools using the following:
conda install -c conda-forge setuptools
That's because you are using an old version of setuptools, check up this issue.
I met the same problem, this is the key:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3
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
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:
https://pypi.org/project/setuptools/
After downloading, unzip the package first, then cd to the directory and run
python setup.py install --user
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
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 distribute-0.7.3.zip (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/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\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/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/dist.py", line 7, in <module>
from setuptools.command.install import install
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/__init__.py", line 8, in <module>
from setuptools.command import install_scripts
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/install_scripts.py", line 3, in <module>
from pkg_resources import Distribution, PathMetadata, ensure_directory
File "/tmp/pip-install-ssqyqflj/distribute/pkg_resources.py", line 1518, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
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:\WINDOWS\system32>python -m pip install slate
The instruction that worked:
C:\WINDOWS\system32>python -m pip install https://github.com/timClicks/slate/archive/master.zip
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:
Download the pip file (pip-version.tar.gz) from:
https://pypi.org/project/pip/#files
For cloud, use this
curl https://files.pythonhosted.org/packages/8e/76/66066b7bc71817238924c7e4b448abdb17eb0c92d645769c223f9ace478f/pip-20.0.2.tar.gz --output pip.tar.gz
Extract the content of the file and cd into the directory.
Run the following in the directory
python3 setup.py install --user
You should have pip3 working without errors.
pip3 install setuptools --upgrade
This also cured the issue on Python 3.9 running on Windows 10 and even on a custom Docker image.
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.
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
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/pkg_resources.py", 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
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.

ImportError: No module named extern

I'm getting this error when trying to install any package with pip. I have two pip instances, one with Python 2.7 and other with Python 3.
Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 375, in setup_py
import setuptools # noqa
File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/usr/local/lib/python2.7/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
ImportError: No module named extern
Even when I try to install the 'extern' module I get this error. Also when installing with Python itself, like python setup.py install.
Thanks in advance.
sudo apt-get purge python-pkg-resources
sudo apt-get -f install
here actually packages are removed and
purged (any configuration files are deleted too).
-f : Attempt to correct a system with broken dependencies in place.
sudo pip install packagename
#sourcehere
Do this it will work
sudo pip install -U setuptools
I know this is an old thread, but I just wanted to contribute since I ran into this issue and this thread kept coming up in the results.
Note: This was on MacOS 10.12. My shell is zsh and I already have brew installed
First I ran each of these commands
brew install python
brew install python3
This will either install it or you'll receive an "already installed" message as I did.
Next, run the following command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
And last:
sudo python get-pip.py
Final note: for my install to work, I ended up having to run the command with pip3
sudo pip3 install nameofinstallhere
Not sure whether it is installation issue or packege but it seems like you will not be able to import any package of them, if you have installed python perfectly then
try this commands
step 1 :
$which pip
/usr/local/bin/pip
step 2 :
/usr/local/bin/pip install django
or any of your package name.
I am considering ubuntu(OS)
You can try the following command; it has worked for me:
sudo apt-get install --reinstall python-setuptools

pip broke. how to fix DistributionNotFound error?

Whenever i try to use pip I get an error. For exampple:
$ sudo pip install gevent-websocket
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1
I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of 'hacking' up my installation...
I'm running python 2.7 and pip is at version 0.8.2.
I find this problem in my MacBook, the reason is because as #Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem.
The resolve is:
easy_install --upgrade pip
Remember: just use one of the above tools to manage your Py packages.
I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.
__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
)
I installed pip through easy_install which probably caused me this headache.
I think this is how you should do it nowadays..
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
I had this issue when I was using homebrew. Here is the solution from Issue #26900
python -m pip install --upgrade --force pip
Try re-installing with the get-pip script:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
This is sourced from the pip Github page, and worked for me.
If you're on CentOS make sure you have the YUM package "python-setuptools" installed
yum install python-setuptools
Fixed it for me.
The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. I'll explain this using problem I encountered myself as an example.
I had virtualenv version 1.10 installed in my user site-packages (the fact it's in user site-packages not sytem site-packages is irrelevant here)
pdobrogost#host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost#host:~$ virtualenv --version
1.10
After I upgraded it to version 1.11 I got the following error:
pdobrogost#host:~$ virtualenv --version
Traceback (most recent call last):
File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
return self.__dep_map
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
if insert:
pkg_resources.DistributionNotFound: virtualenv==1.10
File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:
#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
)
There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.
Now, reinstalling virtualenv like this
pdobrogost#host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
does not help (neither pip install --user --upgrade --force-reinstall virtualenv) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.
The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:
pdobrogost#host:~$ virtualenv --version
1.11
I was able to resolve this like so:
$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source # took ~5 mins
$ python --version # => Python 2.7.9
$ pip install --upgrade pip
I'm running w/ the following stuff (as of Jan 2, 2015):
OS X Yosemite
Version 10.10.1
$ brew -v
Homebrew 0.9.5
$ python --version
Python 2.7.9
$ ipython --version
2.2.0
$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)
$ which pip
/usr/local/bin/pip
I was facing the similar problem in OSx. My stacktrace was saying
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3
Then I did the following
sudo pip install --upgrade setuptools
This solved the problem for me. Hope someone will find this useful.
On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:
C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip
Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew). Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.
I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.
In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.

Categories

Resources