python pip error pkg_resources.DistributionNotFound - python

I'm trying to install a new module, but I found that pip doesn't work - it shows
pkg_resources.DistributionNotFound: The 'pip==1.5.6' distribution was not found and is required by the application
for each call I performed. Also, for pip --help. I found some advises to reinstall pip using pip or easy_install, but easy_install doesn't works too:
pkg_resources.DistributionNotFound: The 'setuptools==5.7' distribution was not found and is required by the application
Is there a way to fix this issue without reinstalling python and all its modules?
I have Linux Ubuntu 14.04.
apt-get install python-pip suggests installing pip (and a heap of another following software) like I don't have it in my system. I afraid to do it, would be a conflict here?
Upd.
apt-get says that it want to install the following: build-essential dpkg-dev fakeroot g++ g++-4.8 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libfakeroot libstdc++-4.8-dev python-chardet-whl python-colorama python-colorama-whl python-distlib python-distlib-whl python-html5lib python-html5lib-whl python-pip python-pip-whl python-requests-whl python-setuptools python-setuptools-whl python-six-whl python-urllib3-whl python-wheel. But as I know pip worked for me without these packages.
Also I performed
which -a python: /usr/bin/python
which -a pip: /usr/local/bin/pip
python --version: Python 2.7.6

It would be useful to have the full backtrace of the error. One scenario that can lead to this issue, is having multiple versions of Python installed.
For example, on my Ubuntu 20.04.1 LTS I have installed Python 3.6 from source, in addition to Python 3.8 distributed with Ubuntu 20. This is what I get with pip3 --version after installing Python 3.6:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 789, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.2.3 (/usr/local/lib/python3.6/site-packages), Requirement.parse('pip==20.0.2'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
#_call_aside
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 583, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 596, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==20.0.2' distribution was not found and is required by the application
The last line is the error in question, but notice an important detail in the traceback: raise VersionConflict.
This can be solved by explicitly using the required version of pip:
$ python3.6 -m pip --version
pip 20.2.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Or simply:
$ pip3.6 --version
pip 20.2.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Another issue one may stumble upon, is the missing lsb_release issue when doing pip3.6 install:
File "/usr/local/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
This can be solved by locating lsb_release.py and creating a symlink, for example:
sudo ln -s /usr/lib/python3/dist-packages/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py
Now it's possible to upgrade pip3.6 and install new packages:
$ pip3.6 install --upgrade pip
$ pip3.6 install mypy
There are different methods for managing Python versions. Beware of using something like sudo update-alternatives --config python. Changing the system's default Python, will likely cause problems, including symptoms like the terminal not opening. It's good to have a backup terminal available, such as the one in Visual Studio Code.

Related

How to install and run virtualenv on MacOS correctly

Hi I'm a beginner of python, I don't remember when and how I installed python3.8 on my Macbook air, only knew the installed path:
% which python
/usr/bin/python
% which python3
/usr/local/bin/python3
The pip command cannot not be found but pip3 is ok. Today I want to install virtaulenv:
% sudo -H pip3 install virtualenv
WARNING: Ignoring invalid distribution - (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages)
Successfully installed virtualenv-20.6.0
I can use "pip3 show virtualenv" to know the info:
% pip3 show virtualenv
Name: virtualenv
Version: 20.6.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Bernat Gabor
Author-email: gaborjbernat#gmail.com
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
Requires: six, platformdirs, backports.entry-points-selectable, distlib, filelock
Required-by:
But when I use "virtualenv" I got command not found message then I "pip3 uninstall" it. I searched for this and got a tip to use "easy_install" to install virtualenv. After installed I can execute the command, but got some error message:
% virtualenv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 583, in _build_master
ws.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'importlib-resources>=1.0' distribution was not found and is required by virtualenv
It seems doesn't work and I try the "sudo pip3 uninstall virtualenv" to uninstall it successfully, but it seems not really be removed:
% which virtualenv
/usr/local/bin/virtualenv
I have no idea about this, could you help me? I just want to run virtualenv normally and create flask project ...
PS. I can "sudo pip3 install flask" and "pip3 show flask" but still cannot run flask cammand (command not found), what should I do?
Thanks a lot!
try being explicit in the version of python you are using and install using -m pip instead
python3 -m pip install virtualenv
python3 -m virtualenv venv # create a new venv in ./venv
source ./venv/bin/activate # activate your new venv
often times the pip/pip3 just isnt pointing at the same python version you think you are using... by using this technique you are sure to be using the correct python and pip

Proper installation of Python 3.6 on Ubuntu 14.06 to include IDLE

I am trying to install Python 3.6 on Ubuntu 14.06. I have tried the get-apt command and I have tried to install from a tarball. Either way this is the error I receive.
:~/Downloads$ pip install Python-43.4.6.tar.gz
Requirement 'Python-43.4.6.tar.gz' looks like a filename, but the file does not exist
Processing ./Python-43.4.6.tar.gz
Exception: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run wb.build(autobuilding=True)
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build self.requirement_set.prepare_files(self.finder)
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 577, in _prepare_file session=self.session, hashes=hashes)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 798, in unpack_url unpack_file_url(link, location, download_dir, hashes=hashes) File "/usr/lib/python2.7/dist-packages/pip/download.py", line 705, in unpack_file_url unpack_file(from_path, location, content_type, link) File "/usr/lib/python2.7/dist-packages/pip/utils/__init__.py", line 620, in unpack_file tarfile.is_tarfile(filename) or
File "/usr/lib/python2.7/tarfile.py", line 2622, in is_tarfile t = open(name)
File "/usr/lib/python2.7/tarfile.py", line 1673, in open return func(name, "r", fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1738, in gzopen fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj)
File "/usr/lib/python2.7/gzip.py", line 94, in __init__ fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
IOError: [Errno 2] No such file or directory: '/home/michael/Downloads/Python-43.4.6.tar.gz'
You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
:~/Downloads$ pip install --upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 662kB/s Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
~/Downloads$ pip -V
pip 9.0.1 from /home/michael/.local/lib/python2.7/site-packages (python 2.7)
~/Downloads$ python -V
Python 2.7.12
~/Downloads$ python3 -V
Python 3.5.2
Did I download the wrong tarball or is there a way to insure that I am not install with for Python 2.7? Also, is the pip version error related?
TIA
First try using the upgrade command in pip and see if that fixes the version problem
pip3 install --upgrade pip
otherwise I would recommend uninstalling and performing a fresh install.
Use the following commands to setup python
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install python3.6 python3-pip idle3
pip3 install numpy
pip3 install spyder
pip3 is the command for using python installer for python3.
to use idle3, just type in into the command window
idle3
I suggest to install spyder using pip3 as spyder is a more advanced idle which can track variables and code writing. makes it a bit easier in locating errors and such.
Many linux distribution provide tkinter, IDLE (which uses tkinter), and turtle (which also uses tkinter) as separate distribution. Searching SO for [tkinter] install tkinter on ubuntu displays previous questions with answers.
sudo apt-get install python3-tk
may be what you need but details may have change since previous answers.

pip broken, reinstall doesn't work. EC2

I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore.
[ec2-user#ip-172-31-17-194 ~]$ sudo pip install validate_email
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3138, in <module>
#_call_aside
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3124, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 663, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 676, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 849, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==6.1.1' distribution was not found and is required by the application
[ec2-user#ip-172-31-17-194 ~]$ which pip
/usr/local/bin/pip
first, which pip is not going to return the same result as sudo which pip, so you should check that out first.
you may also consider not running pip as sudo at all.
Is it acceptable & safe to run pip install under sudo?
second, can you try this:
easy_install --upgrade pip
if you get an error here (regarding pip's wheel support), try this, then run the above command again:
easy_install -U setuptools
I fixed the same error ("The 'pip==6.1.1' distribution was not found") by using the tip of Wesm :
$> which pip && sudo which pip
/usr/local/bin/pip
/usr/bin/pip
So, it seels that "pip" of average user and of root are not the same. Will fix it later.
Then I ran "sudo easy_install --upgrade pip" => succeed
Then I used "sudo /usr/local/bin/pip install " and it works.
Some additional information for anyone who is also stuck on the same issue:-
Running commands with sudo searches for the command in usr/bin directory. One way to solve this issue is to specify the complete path to the command while using sudo as commented by #Cissoid in the question's comment section
Or
...what you can do is create a symbolic link(sym link) to that command in the usr/bin directory using ln command.
$> ln -s /usr/local/bin/pip /usr/bin/pip
The syntax is:-
$> ln -s /path/to/file /path/to/link
I tried a few of these solutions without much success. In the end I just created a new instance using Ubuntu as the operating system. It was already setup properly for using Python properly.
If that is not possible then you can try linking the user pip into a folder on root's (sudo) path.

Python DistributionNotFound Error after installing EB CLI 3.0

Have tried many things, but keep getting this error after multiple attempts to update python, pip, etc. I am on OS X running 10.9.5.
CMD% eb
Traceback (most recent call last):
File "/usr/local/bin/eb", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: python-dateutil>=2.1,<3.0.0
I was experiencing a similar error when trying to run eb, though not for dateutil...
Traceback (most recent call last):
File "/usr/local/bin/eb", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: requests>=2.6.1,<2.7
For me the solution was to update setuptools:
sudo pip install --upgrade setuptools
Hope that helps somebody.
Use the following command:
pip install awsebcli
It will automatically upgrade all dependecies of awsebcli.
use the following command
sudo pip install python-dateutil
to upgrade it
Pip is probably linked to a different version of python then standard.
You should try installing pip using
python get-pip.py
(You can download get-pip.py from the pip website)
Otherwise, You can see which Python everything is linked too.
which python
head -1 $(which eb)
head -1 $(which pip)
You can change to shebang line in the eb script to match pip and it should all work.
You can also install using a virtualenv (pythons recommended way of installing)
virtualenv ~/ebenv
source ~/ebenv/bin/activate
pip install awsebcli
deactivate
sudo ln -s ~/ebenv/bin/eb /usr/local/bin/
in my case on mac osx 10.10, I had to reinstall.
sudo pip install python-dateutil
Just in case some runs into this type of error. check the last paragraph in the trace for the kind of error that it is being raised. In my case, this was:
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (six 1.4.1
(/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
Requirement.parse('six>=1.5'), set(['python-dateutil']))
I had the exact same issue, for me, the eb script was using the wrong python. To solve it I just modified the eb script:
> which eb
/usr/local/bin/eb
> sudo vim /usr/local/bin/eb
## Change the first line from '#!/usr/bin/python' to '#!/usr/local/bin/python'
After restarting the terminal, everything work as expected.
From the raised error in your log, it needs python-dateutil>=2.1.
So you need to make sure that version is installed and install it if not. I had similar issue, and the solution (in my case) is:
$ pip install --ignore-installed python-dateutil==2.2

Why am I getting this error (related to pip and easy_install) when trying to setup a virtualenv?

I'm trying to create a Flask application to push to Heroku. When I try to create a virtualenv in the folder, I'm thrown this error:
photo-crawl › sudo virtualenv venv --distribute
Password:
New python executable in venv/bin/python
Installing distribute............................................................................................................................................................................................................................done.
Installing pip....
Complete output from command /Users/evansiegel/In...rawl/venv/bin/python -x /Users/evansiegel/In...env/bin/easy_install /Library/Python/2.7/...ort/pip-1.2.1.tar.gz:
/Users/evansiegel/Involvio/photo-crawl/venv/bin/python: can't open file '/Users/evansiegel/Involvio/photo-crawl/venv/bin/easy_install': [Errno 2] No such file or directory
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.8.4', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 964, in main
never_download=options.never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1076, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 667, in install_pip
filter_stdout=_filter_setup)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1042, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/evansiegel/In...rawl/venv/bin/python -x /Users/evansiegel/In...env/bin/easy_install /Library/Python/2.7/...ort/pip-1.2.1.tar.gz failed with error code 2
It seems that for some reason virtualenv is not putting everything it should be putting into the venv/bin folder. Right now, only python and two aliases, python2 and python2.7 are in there.
Thanks!
I believe this is caused by a bug in older versions of virtualenv and/or pip. It looks like you're using virtualenv 1.8.4 and pip 1.2.1. Is it possible for you to upgrade to latest virtualenv and pip (currently virtualenv 1.9.1 and pip 1.3.1)?
This should do it, if you have install privileges:
pip install pip --upgrade
pip install virtualenv --upgrade
At that point running the same command (i.e. sudo virtualenv venv --distribute) should give you what you want.

Categories