Pip: Cannot install pip for python3.7 on Ubuntu 16.04 32bits :

Created on 29 Apr 2020  路  15Comments  路  Source: pypa/pip

Environment

  • pip version: Not installed yet for python3.7
  • Python version: Python 3.7.0
  • OS: Ubuntu 16.04 32bits

Description

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

Expected behavior

The installation should be working
How to Reproduce

  1. Run curl -qs https://bootstrap.pypa.io/get-pip.py | sudo -H /usr/bin/python3.7 -

Output

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
ERROR: No matching distribution found for pip
triage

Most helpful comment

@deveshks Pb. solved. After upgrading from Ubuntu 14.04 32b, the deadsnakes repo was disabled and the python3.7 package was NOT upgraded :

$ apt-cache policy python3.7
python3.7:
  Installed: 3.7.0-1+trusty1
  Candidate: 3.7.7-1+xenial1
  Version table:
     3.7.7-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main i386 Packages
 *** 3.7.0-1+trusty1 100
        100 /var/lib/dpkg/status

Now, it is solved :

$ apt-cache policy python3.7
python3.7:
  Installed: 3.7.7-1+xenial1
  Candidate: 3.7.7-1+xenial1
  Version table:
 *** 3.7.7-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main i386 Packages
        100 /var/lib/dpkg/status
$ python3.7 -c "import ssl"
$ curl -qs https://bootstrap.pypa.io/get-pip.py | sudo -H /usr/bin/python3.7 -
Collecting pip
  Using cached pip-20.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Successfully installed pip-20.1
$ pip3.7 -V
pip 20.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

All 15 comments

Just curios, how did you install Python 3.7? If it's from python.org pip should be bundled with it, otherwise if it's from Ubuntu there should be python3-pip matching the Python version. I don't know why this particular problem occurs though.

The relevant code which raises the warning is

https://github.com/pypa/pip/blob/43426eea344c626153efa46f3a9bc6b62d7e8a69/src/pip/_internal/models/search_scope.py#L52-L61

where the has_tls() method checks where _ssl module is available in Python or not.

https://github.com/pypa/pip/blob/43426eea344c626153efa46f3a9bc6b62d7e8a69/src/pip/_internal/utils/compat.py#L77-L86

Can you try import _ssl to verify if the ssl module is present in your python installation? I think that this error might not have to do with pip, but with the underlying python.

There is also IS_PYOPENSSL which tries to see if pyopenssl is available or not, but I couldn't make much sense of how that is used.

Just curios, how did you install Python 3.7? If it's from python.org pip should be bundled with it, otherwise if it's from Ubuntu there should be python3-pip matching the Python version. I don't know why this particular problem occurs though.

@McSinyx I used the deadsnakes PPA repository

Can you try import _ssl to verify if the ssl module is present in your python installation? I think that this error might not have to do with pip, but with the underlying python.

@deveshks

$ /usr/bin/python3.7 -c "import ssl"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

Just curios, how did you install Python 3.7? If it's from python.org pip should be bundled with it, otherwise if it's from Ubuntu there should be python3-pip matching the Python version. I don't know why this particular problem occurs though.

@McSinyx I used the deadsnakes PPA repository

I am not sure how you installed python from the repo you mentioned, but looks like ssl module was not installed. If you use the official ubuntu python release, you can install pip with the instructions present at https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers .

You can also file a support ticket with the repo you used, mentioning how did you install your python, and your issue of not able to find _ssl module, and they might be able to guide you as well. I do see some issues w.r.t this in deadsnakes issues and pip as well

As per https://pip.pypa.io/en/latest/installing/, if your python is from a package manager, it is not advisable to use get-pip.py

@deveshks Pb. solved. After upgrading from Ubuntu 14.04 32b, the deadsnakes repo was disabled and the python3.7 package was NOT upgraded :

$ apt-cache policy python3.7
python3.7:
  Installed: 3.7.0-1+trusty1
  Candidate: 3.7.7-1+xenial1
  Version table:
     3.7.7-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main i386 Packages
 *** 3.7.0-1+trusty1 100
        100 /var/lib/dpkg/status

Now, it is solved :

$ apt-cache policy python3.7
python3.7:
  Installed: 3.7.7-1+xenial1
  Candidate: 3.7.7-1+xenial1
  Version table:
 *** 3.7.7-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main i386 Packages
        100 /var/lib/dpkg/status
$ python3.7 -c "import ssl"
$ curl -qs https://bootstrap.pypa.io/get-pip.py | sudo -H /usr/bin/python3.7 -
Collecting pip
  Using cached pip-20.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Successfully installed pip-20.1
$ pip3.7 -V
pip 20.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

I鈥檝e seen this exact problem popped up occassionally for a while now, which makes me wonder whether pip should fail more gracefully if SSL is unavailable but required (add a link pointing to a post in the error message explaining what鈥檚 going on, for example.)

I鈥檝e seen this exact problem popped up occassionally for a while now, which makes me wonder whether pip should fail more gracefully if SSL is unavailable but required (add a link pointing to a post in the error message explaining what鈥檚 going on, for example.)

@uranusjr If it's not possible to use http only locations, then replace this warning by an error :
ERROR: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
instead of :
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

As per https://pip.pypa.io/en/latest/installing/, if your python is from a package manager, it is not advisable to use get-pip.py

@deveshks I'd love to but deadsnakes does not provide python#.#-pip packages in their PPA repos., that's why I use get-pip.py to install pip.

@deveshks I've just found another command to install pip :

$ sudo -H /usr/bin/python3.7 -m pip install pip -U
Collecting pip
  Using cached https://files.pythonhosted.org/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-20.1

Is this a better way than using get-pip.py if python was installed from apt package manager ?

IIUC, that command might be upgrading the pip which is packaged with the python installation you used. Perhaps you can see which pip and pip --version to be sure.

IIUC, that command might be upgrading the pip which is packaged with the python installation you used. Perhaps you can see which pip and pip --version to be sure.

@deveshks You're right, it did :

$ /usr/bin/pip3 -V
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

What is then the proper way to install pip when a recent version of python was installed from a package manager apt repository ?

I personally don't use Ubuntu, so I am short of suggestions at the moment.

Also I see that pip3 points to python3.5, I thought you had problems installing pip in python3.7?

I personally don't use Ubuntu, so I am short of suggestions at the moment.

Also I see that pip3 points to python3.5, I thought you had problems installing pip in python3.7?

@deveshks /usr/bin/pip3 is installed by the python3-pip package, /usr/local/bin/pip3 came from get-pip.py (or pip python3.7 module from deadsnakes) :

$ which -a pip3 pip3.7
/usr/local/bin/pip3
/usr/bin/pip3
/usr/local/bin/pip3.7
$ dpkg -S /usr/bin/pip3
python3-pip: /usr/bin/pip3
$ /usr/bin/pip3 -V
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
$ /usr/local/bin/pip3 -V
pip 20.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

BTW : /usr/local/bin/pip3 and /usr/local/bin/pip3.7 are the same files :

$ sdiff -s /usr/local/bin/pip3 /usr/local/bin/pip3.7
$

What is then the proper way to install pip when a recent version of python was installed from a package manager apt repository ?

To be honest, the answer is to request that the maintainers of that repository package the latest version of pip.

Or you can do a --user install of pip, but you'll need to make sure your PATH is set correctly, so that your user install gets used in preference to the system install. (And I have a nasty feeling that Ubuntu patches pip in a way that makes user installs slightly non-standard, so you'll need to be prepared for that.

Unfortunately it is all very system-dependent, and not somethingthe pip maintainers can necessarily help with (the wrapper in /usr/bin/pip3 isn't installed or owned by pip, so we have no real control over what it does. The issue #5599 linked in the message you get is the best resource we have for people hitting issues in this area - it's intended for users to share their experiences and help each other out.

Was this page helpful?
0 / 5 - 0 ratings