why does pip installation throw this error? - python

$ sudo easy_install pip ( on mac high sierra)
Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 11, in <module>
load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2707, in load_entry_point
return ep.load()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2325, in load
return self.resolve()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2331, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in <module>
from setuptools.archive_util import unpack_archive
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in <module>
from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile
$ which python
/usr/bin/python
$ which pip
/usr/local/bin/pip
$ which python3
/usr/local/bin/python3

You should try firstly installing pip by using these commands:
sudo apt update
sudo apt install python3-pip
If you are installing it for python2:
sudo apt update
sudo apt install python-pip
Then you can verify the version using:
pip3 --version
Hope this helps.

Here you are having two versions of python installed on your mac.
First is the Python 2.x (which is default) and Python 3.x.
This is a problem I too faced a lot earlier, so what I suggest is this
$sudo apt install python3-pip
This will explicitly install the pip for Python 3.x
And once completed use a virtual environment.

Related

PIP --upgrade not working on Python 3.8.2

I do have Python version 3.8.2 and an outdated version of PIP. I am using a Mac, and when I try to upgrade PIP by doing pip install --upgrade pip I'm getting this error message:
➜ ~ pip install --upgrade pip
Traceback (most recent call last):
File "/usr/local/bin/pip", 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/__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 585, in _build_master
return cls._build_from_requirements(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
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 'pip==18.0' distribution was not found and is required by the application
➜ ~ ```
pip runs the 2.7 pip. Look at the traceback. pip3 runs a 3.x pip, and if 3.8 is the only one, 3.8. python3 -m pip will run some 3.x pip and python3.8 -m pip will only run 3.8 pip. I recommend that you first upgrade to 3.8.7. I forget whether the python.org installer has an option to upgrade pip with it. If not,
python3.8 -m pip install --upgrade pip
should work (I just ran it). If not
python3.8 -m ensurepip
should install a recent pip which can be upgraded.
You will have to reinstall pip manually by following the steps here described.
Donwload get-pip.py
Run python get-pip.py in the folder you downloaded the python script to.
Then, you can use pip normally.

The command 'pip install Somepackage' does not work on Ubuntu 20.04

I have Ubuntu 20.04 installed.
I have python3.8 and python3-pip installed.
however when executing pip install SomePackage I get this error.
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==7.1.0', 'console_scripts', 'pip')()
File "/usr/local/lib/python3.8/dist-packages/pip-7.1.0-py3.8.egg/pip/__init__.py", line 217, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.8/dist-packages/pip-7.1.0-py3.8.egg/pip/basecommand.py", line 216, in main
with self._build_session(
File "/usr/local/lib/python3.8/dist-packages/pip-7.1.0-py3.8.egg/pip/basecommand.py", line 68, in _build_session
session = PipSession(
File "/usr/local/lib/python3.8/dist-packages/pip-7.1.0-py3.8.egg/pip/download.py", line 316, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.8/dist-packages/pip-7.1.0-py3.8.egg/pip/download.py", line 92, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
You are using python 3.x.x. That's why you should use pip3.
Try like this:
pip3 install SomePackage
use this if pip3 doesn't load:
sudo apt install python3-pip
You can also update using this:
python3 -m pip install --upgrade pip

Pip Error : 'module' object has no attribute 'Cryptography_HAS_SSL_ST'

I tried to install from pip and keep on getting similar type of errors.
$ pip install quandl
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 22, in <module>
import requests, six
File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 53, in <module>
import OpenSSL.SSL
File "/home/ubuntu/.local/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/ubuntu/.local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 112, in <module>
if _lib.Cryptography_HAS_SSL_ST:
AttributeError: 'module' object has no attribute 'Cryptography_HAS_SSL_ST'
Now even though i tried to install different pip modules iam getting same error.Is there any solution for this ? This was caused due to the unexpected killing of the process while a pip module is being downloaded.
Please help me with the necessary steps to rectify this error.
I tried to install this
$ pip install -U cryptography
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 22, in <module>
import requests, six
File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 53, in <module>
import OpenSSL.SSL
File "/home/ubuntu/.local/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/ubuntu/.local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 112, in <module>
if _lib.Cryptography_HAS_SSL_ST:
AttributeError: 'module' object has no attribute 'Cryptography_HAS_SSL_ST'
Ubuntu 16.04.3 here:
I think I have fixed this by removing the python-openssl package (and it's dependencies) with:
apt-get --auto-remove remove python-openssl
Then installing the latest version with pip:
pip install pyOpenSSL
Of course, if you install another apt package that depends on it, it'll pull it back in. I hope if you use pip for everything you can from now on instead of apt, it should be fine.
Edit: as of January 2019 this issue doesn't seem to exist any more.
I was able to resolve this by deleting the openssl python lib and reinstalling (purge before install did not work):
$ sudo rm -rf /usr/local/lib/python2.7/dist-packages/OpenSSL/
$ sudo apt install --reinstall python-openssl
If even pip is not working then try following:
sudo easy_install -U cffi
sudo easy_install -U cryptography
It works for me.
To fix it on RHEL/CentOS:
sudo rm -rf /usr/lib/python2.7/site-packages/OpenSSL/
sudo yum install pyOpenSSL
This did it for me on CentOS 7. Cheers!
I got this error and solved it by doing these steps (don't forget to put your own username):
rm -rf /home/<Your Username>/.local/lib/python2.7/site-packages/OpenSSL
sudo rm -rf usr/local/lib/python2.7/dist-packages/OpenSSL/
pip install pyOpenSSL
Try to do the following:
$ rm -rf /home/ubuntu/.local/lib/python2.7/site-packages/OpenSSL
$ rm -rf /home/ubuntu/.local/lib/python2.7/site-packages/pyOpenSSL-0.15.1.egg-info
In the last line, you might have another version of pyOpenSSL, specify yours.
Quick Fix
Move the OpenSSL folder to OpenSSLBAK (for instance) to avoid the error
# cd /usr/lib/python2.7/dist-packages
# mv OpenSSL OpenSSLBAK
It should be good
Try reinstalling python of which will fix many of your problems,do
sudo apt-get install --reinstall python2.7
and pip will be missing after reinstalling,do
sudo apt-get install python-pip
Try to download the suitable wheel file from here depending in your operating system and python version. Then add this file to Python/Scripts and use the code below to install it.
pip install nameofwheelfile.whl
The wheel file contains all the dependencies.

python3.5 pip ImportError: cannot import name 'HTTPSHandler'

everybody.
Firstly,my OS is RHEL7.2,and I use python3.5.
I want to use pip to do something I want.And then ,after I install pip3 successfully,I want to use pip to install something,but it shows me ImportError: cannot import name 'HTTPSHandler'.And I follow the solution on website to yum install openssl-devel,but it shows the error :
Transaction check error:
file /usr/bin/sclient from install of krb5-devel-1.13.2-10.el7.x86_64 conflicts with file from package krb5-server-1.13.2-10.el7.x86_64
file /usr/sbin/sserver from install of krb5-devel-1.13.2-10.el7.x86_64 conflicts with file from package krb5-server-1.13.2-10.el7.x86_64
I can't solve it independently.I hope you can help me.Thanks.
PS:the whole error message is:
[fen#localhost Downloads]$ pip pip-8.0.2-py2.py3-none-any.whl install
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 549, in load_entry_point
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2542, in load_entry_point
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2202, in load
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2208, in resolve
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/_vendor/distlib/scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/_vendor/distlib/compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'
I solved my problem.
I have so many repositories and some data in one repository conflict with another. So I follow the first suggestion: I reinstall krb5-server, and then I yum install openssl-devel and it works well.
After I solve the first problem, I use pip unsuccessfully and I follow the second suggestion: I recompile the python3.5 and the problem is solved.
First check wheather install openssl-develop
sudo apt-get install libssl-dev
or
yum install openssl-dev -y
Try another way to reinstall pip3 ,take Ubuntu for example
sudo apt-get install python3-setuptools
sudo easy_install3 pip
use setuptools to install pip may can solve the problem of dependency.
Try it on RHEL
sudo yum install -y python35-setuptools
sudo easy_install-3.5 pip

pip Not Working Python 2.7

I am having a problem with pip just now, when I try to install something like pip install readline then I get an error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 549, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2709, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2369, in load
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2375, in resolve
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead
So I ran cat /usr/local/bin/pip which tells me pip==1.5.6. I tried to find a solution online regarding this and one solution told to cd /usr/local/lib/python2.7/site-packages && ls but for me I see that folder is also empty.
If upgrading pip doesn't work, you should try uninstalling it and reinstalling it. The error you're encountering is likely due to a mismatch in versions between pip and requests. First, I would remove pip and reinstall it from the source with python like this:
sudo apt-get remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
From the Ubuntu launchpad site
Just check If You have installed python-setuptools rpm, If this is installed You can use easy_install pip on Redhat Based System.
I would comment this but due to low reputation I can't. Did you try upgrading pip?
pip install --upgrade pip
And then try to do that again.
If you are using Debian flavor OS (like Ubuntu) try this
apt-get remove python-pip
Then try to install the latest version by easy_install
easy_install pip

Categories