Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
使用pip安装python包时遇到HTTPSHandler错误,以下是堆栈跟踪,
--------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
我以前编辑Modules / setup.dist文件并取消注释SSL代码行并重新构建它,参考以下主题:http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse -python-的OpenSSL 2.HTML
11 个解决方案
#1
47
OSX + homebrew users:
You can get the latest updates to the recipe:
您可以获得配方的最新更新:
brew reinstall python
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
但是如果你仍然遇到问题,例如也许你已经升级了你的操作系统,那么你可能需要先获得最新的openssl。您可以从以下位置检查使用的版本和位置:
openssl version -a
which openssl
To get the latest openssl:
要获得最新的openssl:
brew update
brew install openssl
brew link --overwrite --dry-run openssl # safety first.
brew link openssl --overwrite
This may issue a warning:
这可能会发出警告:
bash-4.3$ brew link --overwrite --dry-run 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
Side note: this warning means that for other apps, you may want to use
附注:此警告表示对于其他应用程序,您可能希望使用
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
Then recompile python:
然后重新编译python:
brew uninstall python
brew install python --with-brewed-openssl
or for python 3
或者对于python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
#2
22
You need to install the OpenSSL header files before building Python if you need SSL support. On Debian and Ubuntu, they are in a package called libssl-dev
. You might need some more dependencies, as noted here.
如果需要SSL支持,则需要在构建Python之前安装OpenSSL头文件。在Debian和Ubuntu上,它们位于一个名为libssl-dev的包中。您可能需要更多依赖项,如此处所述。
#3
19
Homebrew
This was probably caused by an upgrade to Mavericks. Here's how I fixed it.
这可能是由于升级到小牛队造成的。这是我修复它的方法。
Update OpenSSL
#make a copy of the existing library, just in case
sudo cp /usr/bin/openssl /usr/bin/openssl.apple
# update openssl
brew update
brew install openssl
brew link --force openssl
# reload terminal paths
hash -r
Reinstall Python
Python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
Python 2
brew uninstall python
brew install python --with-brewed-openssl
This answer consolidates all the Stack Exchange answers and comments I found, and is based mostly on this Apple Stack Exchange answer.
这个答案整合了我发现的所有Stack Exchange答案和评论,主要基于Apple Stack Exchange的答案。
#4
9
I was having this problem on Mac OSX, even after confirming my PATH, etc.
即使在确认我的PATH等之后,我在Mac OSX上遇到了这个问题。
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
做了一个;点击卸载virtualenv然后安装virtualenv它似乎现在工作。
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.
当时我强迫brew连接openssl,取消关联它和virtualenv似乎仍然有用但也许那是因为它最初是在我重新安装时链接的。
#5
9
You need to install OpenSSl before make and install Python to solve the problem.
您需要在make之前安装OpenSSl并安装Python来解决问题。
On Centos:
在Centos上:
yum install openssl openssl-devel -y
资源
#6
6
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:
这个问题的另一个症状是,如果我进入我的virtualenv的python控制台并且导入ssl它会出错。事实证明我的virtualenv没有使用brew版本的python,只是我机器上的默认安装。不知道为什么默认安装突然停止工作,但这是我如何修复它的问题:
rmvirtualenv myvirtualenv
- rmvirtualenv myvirtualenv
brew update
- brew更新
brew reinstall python
- brew重新安装python
mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv
- mkvirtualenv -p / usr / local / Cellar / python / whatever_version_number / bin / python myvirtualenv
#7
4
It seems your pip
requires HTTPSHandler
which is part of SSL
library.
看来你的pip需要HTTPSHandler,这是SSL库的一部分。
OSX
OSX
On OS X you should link OpenSSL during Python installation (See: #14497).
在OS X上,您应该在Python安装期间链接OpenSSL(参见:#14497)。
For Python 2:
对于Python 2:
brew reinstall python --with-brewed-openssl
pip install --upgrade pip
For Python 3:
对于Python 3:
brew reinstall python3 --with-brewed-openssl
pip3 install --upgrade pip
You could have multiple Python instances together, to list them run:
你可以将多个Python实例放在一起,列出它们运行:
brew list | grep ^python
Or list your version via ls -al /usr/local/lib/python*
.
或者通过ls -al / usr / local / lib / python *列出你的版本。
#8
3
I'm using Redhat and have met the same problem.
我正在使用Redhat并遇到了同样的问题。
My solution is :
我的解决方案是:
- install openssl and openssl-devel ---- yum install openssl openssl-devel -y
- 安装openssl和openssl-devel ---- yum install openssl openssl-devel -y
- install krb5-devel ---- yum install krb5-devel
- 安装krb5-devel ---- yum install krb5-devel
- change to your python's directory and recompile it ---- make
- 更改到python的目录并重新编译它---- make
If I didn't do the 2nd step, when I recompiled my python2.7 , the log would say " fail to build module _ssl".
如果我没有做第二步,当我重新编译我的python2.7时,日志会说“无法构建模块_ssl”。
#9
0
In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
在许多情况下,这是由过时的virtualenv引起的,这是一个重新生成virtualenv的脚本:https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
Simply copy it to a file (downloadable link above) and execute it like this: zsh -e recreate_virtualenvs.sh <project_name>
只需将其复制到一个文件(上面的可下载链接)并执行如下:zsh -e recreate_virtualenvs.sh
#!/bin/zsh -e
if [ ! -d "$PROJECT_HOME" ]; then
echo 'Your $PROJECT_HOME needs to be defined'
echo 'http://virtualenvwrapper.readthedocs.org/en/latest/install.html#location-of-project-directories'
exit 1
fi
if [ "" = "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
env="$1"
project_dir="$PROJECT_HOME/$1"
env_dir="$HOME/envs/$1"
function command_exists(){
type $1 2>/dev/null | grep -vq ' not found'
}
if command_exists workon; then
echo 'Getting virtualenvwrapper from environment'
# Workon exists, nothing to do :)
elif [ -x ~/bin/mount_workon ]; then
echo 'Using mount workon'
# Optional support for packaged project directories and virtualenvs using
# https://github.com/WoLpH/dotfiles/blob/master/bin/mount_workon
. ~/bin/mount_workon
mount_file "$project_dir"
mount_file "$env_dir"
elif command_exists virtualenvwrapper.sh; then
echo 'Using virtualenvwrapper'
. $(which virtualenvwrapper.sh)
fi
if ! command_exists workon; then
echo 'Virtualenvwrapper not found, please install it'
exit 1
fi
rmvirtualenv $env || true
echo "Recreating $env"
mkvirtualenv $env || true
workon "$env" || true
pip install virtualenv{,wrapper}
cd $project_dir
setvirtualenvproject
if [ -f setup.py ]; then
echo "Installing local package"
pip install -e .
fi
function install_requirements(){
# Installing requirements from given file, if it exists
if [ -f "$1" ]; then
echo "Installing requirements from $1"
pip install -r "$1"
fi
}
install_requirements requirements_test.txt
install_requirements requirements-test.txt
install_requirements requirements.txt
install_requirements test_requirements.txt
install_requirements test-requirements.txt
if [ -d docs ]; then
echo "Found docs, installing sphinx"
pip install sphinx{,-pypi-upload} py
fi
echo "Installing ipython"
pip install ipython
if [ -f tox.ini ]; then
deps=$(python -c "
parser=__import__('ConfigParser').ConfigParser();
parser.read('tox.ini');
print parser.get('testenv', 'deps').strip().replace('{toxinidir}/', '')")
echo "Found deps from tox.ini: $deps"
echo $deps | parallel -v --no-notice pip install {}
fi
if [ -f .travis.yml ]; then
echo "Found deps from travis:"
installs=$(grep 'pip install' .travis.yml | grep -v '\$' | sed -e 's/.*pip install/pip install/' | grep -v 'pip install . --use-mirrors' | sed -e 's/$/;/')
echo $installs
eval $installs
fi
deactivate
#10
0
On OSX, brew kept refusing to link against its openssl with this error:
在OSX上,brew一直拒绝使用此错误链接其openssl:
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
#11
0
For Ubuntu
First check wheather install openssl-develop
首先检查一下安装openssl-develop
sudo apt-get install libssl-dev
Try another way to reinstall pip
尝试另一种方法重新安装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.
使用setuptools来安装pip而不是用源代码安装可以解决依赖问题。
#1
47
OSX + homebrew users:
You can get the latest updates to the recipe:
您可以获得配方的最新更新:
brew reinstall python
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
但是如果你仍然遇到问题,例如也许你已经升级了你的操作系统,那么你可能需要先获得最新的openssl。您可以从以下位置检查使用的版本和位置:
openssl version -a
which openssl
To get the latest openssl:
要获得最新的openssl:
brew update
brew install openssl
brew link --overwrite --dry-run openssl # safety first.
brew link openssl --overwrite
This may issue a warning:
这可能会发出警告:
bash-4.3$ brew link --overwrite --dry-run 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
Side note: this warning means that for other apps, you may want to use
附注:此警告表示对于其他应用程序,您可能希望使用
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
Then recompile python:
然后重新编译python:
brew uninstall python
brew install python --with-brewed-openssl
or for python 3
或者对于python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
#2
22
You need to install the OpenSSL header files before building Python if you need SSL support. On Debian and Ubuntu, they are in a package called libssl-dev
. You might need some more dependencies, as noted here.
如果需要SSL支持,则需要在构建Python之前安装OpenSSL头文件。在Debian和Ubuntu上,它们位于一个名为libssl-dev的包中。您可能需要更多依赖项,如此处所述。
#3
19
Homebrew
This was probably caused by an upgrade to Mavericks. Here's how I fixed it.
这可能是由于升级到小牛队造成的。这是我修复它的方法。
Update OpenSSL
#make a copy of the existing library, just in case
sudo cp /usr/bin/openssl /usr/bin/openssl.apple
# update openssl
brew update
brew install openssl
brew link --force openssl
# reload terminal paths
hash -r
Reinstall Python
Python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
Python 2
brew uninstall python
brew install python --with-brewed-openssl
This answer consolidates all the Stack Exchange answers and comments I found, and is based mostly on this Apple Stack Exchange answer.
这个答案整合了我发现的所有Stack Exchange答案和评论,主要基于Apple Stack Exchange的答案。
#4
9
I was having this problem on Mac OSX, even after confirming my PATH, etc.
即使在确认我的PATH等之后,我在Mac OSX上遇到了这个问题。
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
做了一个;点击卸载virtualenv然后安装virtualenv它似乎现在工作。
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.
当时我强迫brew连接openssl,取消关联它和virtualenv似乎仍然有用但也许那是因为它最初是在我重新安装时链接的。
#5
9
You need to install OpenSSl before make and install Python to solve the problem.
您需要在make之前安装OpenSSl并安装Python来解决问题。
On Centos:
在Centos上:
yum install openssl openssl-devel -y
资源
#6
6
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:
这个问题的另一个症状是,如果我进入我的virtualenv的python控制台并且导入ssl它会出错。事实证明我的virtualenv没有使用brew版本的python,只是我机器上的默认安装。不知道为什么默认安装突然停止工作,但这是我如何修复它的问题:
rmvirtualenv myvirtualenv
- rmvirtualenv myvirtualenv
brew update
- brew更新
brew reinstall python
- brew重新安装python
mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv
- mkvirtualenv -p / usr / local / Cellar / python / whatever_version_number / bin / python myvirtualenv
#7
4
It seems your pip
requires HTTPSHandler
which is part of SSL
library.
看来你的pip需要HTTPSHandler,这是SSL库的一部分。
OSX
OSX
On OS X you should link OpenSSL during Python installation (See: #14497).
在OS X上,您应该在Python安装期间链接OpenSSL(参见:#14497)。
For Python 2:
对于Python 2:
brew reinstall python --with-brewed-openssl
pip install --upgrade pip
For Python 3:
对于Python 3:
brew reinstall python3 --with-brewed-openssl
pip3 install --upgrade pip
You could have multiple Python instances together, to list them run:
你可以将多个Python实例放在一起,列出它们运行:
brew list | grep ^python
Or list your version via ls -al /usr/local/lib/python*
.
或者通过ls -al / usr / local / lib / python *列出你的版本。
#8
3
I'm using Redhat and have met the same problem.
我正在使用Redhat并遇到了同样的问题。
My solution is :
我的解决方案是:
- install openssl and openssl-devel ---- yum install openssl openssl-devel -y
- 安装openssl和openssl-devel ---- yum install openssl openssl-devel -y
- install krb5-devel ---- yum install krb5-devel
- 安装krb5-devel ---- yum install krb5-devel
- change to your python's directory and recompile it ---- make
- 更改到python的目录并重新编译它---- make
If I didn't do the 2nd step, when I recompiled my python2.7 , the log would say " fail to build module _ssl".
如果我没有做第二步,当我重新编译我的python2.7时,日志会说“无法构建模块_ssl”。
#9
0
In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
在许多情况下,这是由过时的virtualenv引起的,这是一个重新生成virtualenv的脚本:https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
Simply copy it to a file (downloadable link above) and execute it like this: zsh -e recreate_virtualenvs.sh <project_name>
只需将其复制到一个文件(上面的可下载链接)并执行如下:zsh -e recreate_virtualenvs.sh
#!/bin/zsh -e
if [ ! -d "$PROJECT_HOME" ]; then
echo 'Your $PROJECT_HOME needs to be defined'
echo 'http://virtualenvwrapper.readthedocs.org/en/latest/install.html#location-of-project-directories'
exit 1
fi
if [ "" = "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
env="$1"
project_dir="$PROJECT_HOME/$1"
env_dir="$HOME/envs/$1"
function command_exists(){
type $1 2>/dev/null | grep -vq ' not found'
}
if command_exists workon; then
echo 'Getting virtualenvwrapper from environment'
# Workon exists, nothing to do :)
elif [ -x ~/bin/mount_workon ]; then
echo 'Using mount workon'
# Optional support for packaged project directories and virtualenvs using
# https://github.com/WoLpH/dotfiles/blob/master/bin/mount_workon
. ~/bin/mount_workon
mount_file "$project_dir"
mount_file "$env_dir"
elif command_exists virtualenvwrapper.sh; then
echo 'Using virtualenvwrapper'
. $(which virtualenvwrapper.sh)
fi
if ! command_exists workon; then
echo 'Virtualenvwrapper not found, please install it'
exit 1
fi
rmvirtualenv $env || true
echo "Recreating $env"
mkvirtualenv $env || true
workon "$env" || true
pip install virtualenv{,wrapper}
cd $project_dir
setvirtualenvproject
if [ -f setup.py ]; then
echo "Installing local package"
pip install -e .
fi
function install_requirements(){
# Installing requirements from given file, if it exists
if [ -f "$1" ]; then
echo "Installing requirements from $1"
pip install -r "$1"
fi
}
install_requirements requirements_test.txt
install_requirements requirements-test.txt
install_requirements requirements.txt
install_requirements test_requirements.txt
install_requirements test-requirements.txt
if [ -d docs ]; then
echo "Found docs, installing sphinx"
pip install sphinx{,-pypi-upload} py
fi
echo "Installing ipython"
pip install ipython
if [ -f tox.ini ]; then
deps=$(python -c "
parser=__import__('ConfigParser').ConfigParser();
parser.read('tox.ini');
print parser.get('testenv', 'deps').strip().replace('{toxinidir}/', '')")
echo "Found deps from tox.ini: $deps"
echo $deps | parallel -v --no-notice pip install {}
fi
if [ -f .travis.yml ]; then
echo "Found deps from travis:"
installs=$(grep 'pip install' .travis.yml | grep -v '\$' | sed -e 's/.*pip install/pip install/' | grep -v 'pip install . --use-mirrors' | sed -e 's/$/;/')
echo $installs
eval $installs
fi
deactivate
#10
0
On OSX, brew kept refusing to link against its openssl with this error:
在OSX上,brew一直拒绝使用此错误链接其openssl:
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
#11
0
For Ubuntu
First check wheather install openssl-develop
首先检查一下安装openssl-develop
sudo apt-get install libssl-dev
Try another way to reinstall pip
尝试另一种方法重新安装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.
使用setuptools来安装pip而不是用源代码安装可以解决依赖问题。