ImportError: cannot import name HTTPSHandler using PIP

后端 未结 12 1849
刺人心
刺人心 2020-11-28 07:35

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

--------desktop:~$ pip install Django==1.3
Traceback (         


        
相关标签:
12条回答
  • 2020-11-28 07:45

    Just installed ssl pyopenssl

    pip install pyopenssl
    
    0 讨论(0)
  • 2020-11-28 07:46

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

    On Centos:

    yum install openssl openssl-devel -y
    

    source

    0 讨论(0)
  • 2020-11-28 07:47

    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.

    0 讨论(0)
  • 2020-11-28 07:48

    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.

    0 讨论(0)
  • 2020-11-28 07:50

    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

    Simply copy it to a file (downloadable link above) and execute it like this: 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
    
    0 讨论(0)
  • 2020-11-28 07:51

    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
    0 讨论(0)
提交回复
热议问题