“ssl module in Python is not available” when installing package with pip3

后端 未结 28 1432
别跟我提以往
别跟我提以往 2020-11-22 08:51

I\'ve install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3.

When I execute pip3 install

相关标签:
28条回答
  • 2020-11-22 09:06

    In my case with using Mac, I deleted /Applications/Python 3.7. because I already had Python3.7 by brew install python3 .

    But it was a trigger of the message

    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

    What I did in my situation

    1. I downloaded macOS 64-bit installer again, and installed.
    2. Double click /Applications/Python3.6/Install Certificates.command and /Applications/Python3.6/Update Shell Profile.command.
    3. Reboot mac
    4. And I am not sure but possibly contributed to succeed is pip.conf. See pip install fails.
    0 讨论(0)
  • 2020-11-22 09:06

    Ok the latest answer to this, as of now don't use Python 3.8, use only 3.7 or less , because of most of the libraries fail to install with the above error

    0 讨论(0)
  • 2020-11-22 09:07

    I was having the same issue and was able to resolve with the following steps:

    sudo yum install -y libffi-devel
    sudo yum install openssl-devel
    cd /usr/src
    sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
    sudo tar xf Python-3.7.1.tar.xz
    cd Python-3.7.1
    sudo ./configure --enable-optimizations
    # Install into /usr/local/bin/python3.7, don't overwrite global python bin
    sudo make altinstall
    

    depending on perms, you may not need sudo.

    Results:
    Collecting setuptools
    Collecting pip
    Installing collected packages: setuptools, pip
    Successfully installed pip-10.0.1 setuptools-39.0.1
    

    should now be able to run

    python3.7 -V 
    

    and

    pip3.7 -V
    

    When installing packages:

    pip3.7 install pandas
    

    or depending on perms, you can also add the --user flag like so:

    pip3.7 install pandas --user
    
    0 讨论(0)
  • 2020-11-22 09:07

    In the case of using pyenv to manage python installations on Mac OS Catalina, I had to install openssl with brew first and then after that run pyenv install 3.7.8 which seemed to build the python installation using the openssl from homebrew (it even said as such in the installation output). Then pyenv global 3.7.8 and I was away.

    0 讨论(0)
  • 2020-11-22 09:09

    The ssl module is a TLS/SSL wrapper for accessing Operation Sytem (OS) socket (Lib/ssl.py). So when ssl module is not available, chances are that you either don't have OS OpenSSL libraries installed, or those libraries were not found when you install Python. Let assume it is a later case (aka: you already have OpenSSL installed, but they are not correctly linked when installing Python).

    I will also assume you are installing from source. If you are installing from binary (ie: Window .exe file), or package (Mac .dmg, or Ubuntu apt), there is not much you can do with the installing process.

    During the step of configuring your python installation, you need to specify where the OS OpenSSL will be used for linking:

    # python 3.8 beta
    ./configure --with-openssl="your_OpenSSL root"
    

    So where will you find your installed OpenSSL directory?

    # ubuntu 
    locate ssl.h | grep '/openssl/ssl.h'
    
    /home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
    /home/user/envs/py37/include/openssl/ssl.h
    /home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
    /home/user/miniconda3/include/openssl/ssl.h
    /home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
    /home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
    /home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
    /usr/include/openssl/ssl.h
    

    Your system may be different than mine, but as you see here I have many different installed openssl libraries. As the time of this writing, python 3.8 expects openssl 1.0.2 or 1.1:

    Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().

    So you would need to verify which of those installed libraries that you can use for linking, for example

    /usr/bin/openssl version
    
    OpenSSL 1.0.2g  1 Mar 2016
    
    ./configure --with-openssl="/usr"
    make && make install
    

    You may need to try a few, or install a new, to find the library that would work for your Python and your OS.

    0 讨论(0)
  • 2020-11-22 09:09

    I had the same issue with python3.8.5 installation on Debian9. I have done a build, but when I have tried to download some modules, pip3.8 issued following error:

    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    

    I have searched for the root of my problem and found out that there is a system dependent portion of the python build which is called by system independent one. In case of missing ssl you just needed to open python terminal and check whether is _ssl present:

    >>> help('modules')
    .
    .
    _sre                enum                pwd                 wave
    _ssl                errno               py_compile          weakref
    _stat               faulthandler        pyclbr              webbrowser
    .
    .
    

    If not your system dependent ssl module part is missing. You can check it also by listing content of <python_installation_root>/lib/python3.8/lib-dynload:

    >ls ./lib/python3.8/lib-dynload | grep ssl
    _ssl.cpython-38-x86_64-linux-gnu.so
    

    The problem was caused as written by PengShaw by missing libssl-dev during the build. Therefore you have to follow the recommended python installation flow. First install prerequisites and then build and install the python. Installation without devel versions of libs resulted in my case in the missing system dependent part. In this case _ssl.

    Note that the devel lib name differs for Debian and CentOS, therefore check whether the installation hints posted on net are suitable for your specific Linux system type:

    For Debian:
    sudo apt install -y libbz2-dev libffi-dev libssl-dev
    ./configure --enable-optimizations
    make
    make altinstall
    
    
    For CentOS:
    sudo yum -y install bzip2-devel libffi-devel openssl-devel
    ./configure --enable-optimizations
    make
    make altinstall
    

    It is for sure a good idea to list configuration options prior the configuration and evtl. use some additional options:

    ./configure --help
    

    Last but not least in case you use --prefix for a non-default installation location, remember to add your <python_installation_root>/lib to your LD_LIBRARY_PATH .

    0 讨论(0)
提交回复
热议问题