2013-12-19 94 views
58

在安裝使用PIP Python包面臨HTTPSHandler錯誤不能導入名稱HTTPSHandler,以下是堆棧跟蹤,導入錯誤:使用PIP

--------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 

我用來編輯模塊/ setup.dist文件,取消SSL行代碼並參照以下線程重建:http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html

+1

你是怎麼安裝python的?你可以在python shell中導入ssl或import _ssl嗎? – sk1p

+0

你在什麼系統上? – sk1p

+1

我做了./configure,make,sudo make altinstall,然後用虛擬env添加python2.7;但是在做點子時它會返回相同的錯誤。 import ssl「ImportError:No module named _ssl」。同樣使用--with-ssl重新創建,並在Modules/Setup.dist中對可下載的ssl行取消註釋。 – user3016020

回答

22

如果需要SSL支持,則需要在構建Python之前安裝OpenSSL頭文件。在Debian和Ubuntu上,它們在名爲libssl-dev的包中。您可能需要一些更多的依賴項,as noted here

+0

嘿感謝,是的,它需要一些依賴,它現在正在工作。 – user3016020

+0

如何讓我們工作? –

9

您需要在安裝Python之前安裝OpenSSl來解決問題。

在CentOS:

yum install openssl openssl-devel -y 

source

+1

我安裝了openssl,但我仍然有一個問題,用於構建python 2.7.10 – HDJEMAI

+0

消息:python get-pip.py Traceback(最近調用最後一個): 文件「get-pip.py」,第17759行,在 主() 文件 「get-pip.py」,線162,在主 自舉(TMPDIR = TMPDIR) 文件 「get-pip.py」,線82,在自舉 進口PIP – HDJEMAI

+0

文件「/ TMP/「/ tmpVpnhQ/pip.zip/pip/__ init__.py」,第15行,在 文件「/tmp/tmpaVpnhQ/pip.zip/pip/vcs/subversion.py」,第9行,在 文件「/ tmp/tmpaVpnhQ/pip.zip/pip/index.py「,第30行,在 文件「/tmp/tmpaVpnhQ/pip.zip/pip/wheel.py」,第35行,在 文件「/tmp/tmpaVpnhQ/pip.zip/pip/_vendor/distlib/scripts.py」,第14行,在 文件「/tmp/tmpaVpnhQ/pip.zip/pip/_vendor/distlib/compat.py」 31行,在 導入錯誤:無法導入名稱HTTPSHandler – HDJEMAI

9

我在Mac OSX上這個問題,甚至確認我路徑後,等

沒過;點卸載virtualenv然後安裝virtualenv,它似乎現在起作用。

當時我強制brew連接openssl,取消關聯它和virtualenv仍然似乎工作,但也許這是因爲它是最初連接時,我重新安裝它。

6

對我來說,這個問題的另一個症狀是,如果我進入我的virtualenv的python控制檯,並做了import ssl它會出錯。原來我的virtualenv沒有使用python的brew版本,只是我機器上的默認安裝。不知道爲什麼默認安裝突然停止工作,但這裏是我是如何解決它的問題:

  • rmvirtualenv myvirtualenv
  • brew update
  • brew reinstall python
  • mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv
+0

丹尼爾和我得到一個權限被拒絕的錯誤。任何想法? –

+1

我應該一直指向'/ usr/local/Cellar/python/whatever_version_number/bin/python'而不是'/ usr/local/Cellar/python/whatever_version_number /'在上面做了更改。我希望你和丹尼爾能夠工作。 –

0

在許多情況下,這是造成由過時的virtualenv,這是一個腳本來重新生成你的虛擬機:https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8

只需將它複製到文件(以上下載鏈接),然後執行它是這樣的:zsh -e recreate_virtualenvs.sh <project_name>

#!/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 
46

OSX +自制用戶:

你可以得到最新的更新到配方:

brew reinstall python 

但是,如果您仍然遇到問題,例如也許你升級了你的操作系統,那麼你可能需要先獲得最新的openssl。您可以檢查哪些版本,它是從哪裏使用:

openssl version -a 
which openssl 

要獲得最新的OpenSSL:

brew update 
brew install openssl 
brew link --overwrite --dry-run openssl # safety first. 
brew link openssl --overwrite 

這可能發出警告:

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 

邊注:此警告意味着對於其他應用程序,您可能需要使用

export LDFLAGS=-L/usr/local/opt/openssl/lib 
export CPPFLAGS=-I/usr/local/opt/openssl/include 

然後重新編譯蟒蛇:

brew uninstall python 
brew install python --with-brewed-openssl 

或蟒蛇3

brew uninstall python3 
brew install python3 --with-brewed-openssl 
+2

不要以爲這會工作,如果你有多個python版本安裝 – tdc

+2

'bash-4.3 $ brew link --overwrite --dry-run openssl 警告:拒絕鏈接:openssl 鏈接桶只有openssl意味着你可能會結束在使用Homebrew的openssl的頭文件時,不贊成使用系統OpenSSL。 而是將完整的include /庫路徑傳遞給您的編譯器,例如: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib' –

4

看來你pip需要HTTPSHandler這是SSL庫的一部分。

OSX

在OS X上,你應該Python安裝過程中鏈接的OpenSSL(請參見:#14497)。

對於Python 2:

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

對於Python 3:

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

你可以有多個Python的情況下一起,列出它們運行:

brew list | grep ^python 

或者列出你的版本通過ls -al /usr/local/lib/python*

19

自制蛋白

這可能是由於升級到小牛造成的。這是我如何修復它。

更新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 

重新安裝Python的

的Python 3

brew uninstall python3 

brew install python3 --with-brewed-openssl 

的Python 2

brew uninstall python 

brew install python --with-brewed-openssl 

這個答案將所有堆棧交易所答案s和我發現的評論,並且主要基於這個Apple Stack Exchange answer

+0

謝謝!這也適用於OS X El Capitan。 –

+0

Prefect,我得到了El Capitan 10.11測試版中的'ImportError:can not import name HTTPSHandler',我剛剛使用'brew update'和'brew install openssl',因爲我已經安裝了pip和python。謝謝 – Perspective

+0

謝謝!注意:'brew升級'不僅可以重新安裝python,還可以同時安裝其他可能過時的模塊。這可能需要幾分鐘,具體取決於您已安裝的其他東西。 – christang

3

我正在使用Redhat並遇到同樣的問題。

我的解決辦法是:

  1. 安裝OpenSSL和OpenSSL的-devel的----百勝安裝的OpenSSL的OpenSSL devel的-y
  2. 安裝的krb5-devel的----百勝安裝的krb5-devel的
  3. 改變你的Python的目錄,並重新編譯它----讓

如果我沒有做第2步,當我重新編譯我的python2.7,日誌會說:「不能夠培養模塊_ssl」。

0

在OSX,釀造不斷拒絕反對它的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 

我終於能得到它的工作:

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 
0

的Ubuntu

第一檢查是否安裝openssl-develop

sudo apt-get install libssl-dev 

嘗試另一種方式重新安裝pip

sudo apt-get install python-setuptools 
sudo easy_install pip 

使用setuptools安裝點子,而不是源代碼安裝可能可以解決依賴問題。