ImportError: cannot import name HTTPSHandler using

2019-01-06 12:39发布

Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,

--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
  File "/home/env/.genv/bin/pip", line 9, in <module>
    load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/home/env/.genv/lib/python2.7/site-packages/pip/__init__.py", line 10, in <module>
    from pip.util import get_installed_distributions, get_prog
  File "/home/env/.genv/lib/python2.7/site-packages/pip/util.py", line 17, in <module>
    from pip.vendor.distlib import version
  File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in <module>
    from .compat import string_types
  File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in <module>
    from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler

I used to edit Modules/setup.dist file and uncomment SSL code lines and rebuilt it, with reference to following thread : http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html

11条回答
狗以群分
2楼-- · 2019-01-06 13:08

I was having this problem on Mac OSX, even after confirming my PATH, etc.

Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.

At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstalled it.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-06 13:08

On OSX, brew kept refusing to link against its openssl with this error:

15:27 $ brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

I finally was able to get it working with:

  brew remove openssl
  brew uninstall --force openssl
  brew install openssl
  export LDFLAGS=-L/usr/local/opt/openssl/lib
  export CPPFLAGS=-I/usr/local/opt/openssl/include
  brew remove python
  brew update
  brew install python
查看更多
劳资没心,怎么记你
4楼-- · 2019-01-06 13:11

You need to install OpenSSl before make and install Python to solve the problem.

On Centos:

yum install openssl openssl-devel -y

source

查看更多
干净又极端
5楼-- · 2019-01-06 13:11

For Ubuntu

First check wheather install openssl-develop

sudo apt-get install libssl-dev

Try another way to reinstall pip

sudo apt-get install python-setuptools
sudo easy_install pip

use setuptools to install pip rather than install with source code may can solve the problem of dependency.

查看更多
乱世女痞
6楼-- · 2019-01-06 13:14

It seems your pip requires HTTPSHandler which is part of SSL library.

OSX

On OS X you should link OpenSSL during Python installation (See: #14497).

For Python 2:

brew reinstall python --with-brewed-openssl
pip install --upgrade pip

For Python 3:

brew reinstall python3 --with-brewed-openssl
pip3 install --upgrade pip

You could have multiple Python instances together, to list them run:

brew list | grep ^python

Or list your version via ls -al /usr/local/lib/python*.

查看更多
干净又极端
7楼-- · 2019-01-06 13:15

Another symptom of this problem for me was if I went into the python console of my virtualenv and did import ssl it would error out. Turns out my virtualenv wasn't using the brew version of python, just the default install on my machine. No clue why the default install suddenly stopped working, but here's how I fixed it the problem:

  • rmvirtualenv myvirtualenv
  • brew update
  • brew reinstall python
  • mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv
查看更多
登录 后发表回答