0

In a virtual environment activated in a virtual machine, I can't install any package with pip, since it raises a SSL related error.

I'm setting up a virtual environment (with virtualenv) to mimic the the settings of a server that I'm going to work with. So I installed mannualy (from tar file) a specific version of python (3.7.0) in a Ubuntu 18.04 virtual machine (using VirtualBox). Once my python version of choice was running I activated a virtual environment. The pip version is 18.1.

The problem comes when I try to install a python package, like:

$ pip install django

It raised this error:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting django
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/django/
Could not fetch URL https://pypi.org/simple/django/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/django/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django

Neither of the answers that I found after searching helped me. Since pip can't install anything, it can't install packages like ssl nor OpenSSL. If anyone can help me, I thank a lot in advance.

handraqui
  • 11
  • 3
  • Can you use Ubuntu's package manager to install python3.7 instead of using a tar file? Then, for one, you'd probably get the ssl module (which is part of the standard library) by default. Otherwise, you probably need to get the ssl library into your tarball. How did you make the tarball? – JawguyChooser Jan 16 '19 at 18:16
  • 2
    If you compiled python from source tarball, then you didn't link against OpenSSL and thus no SSL module. The solution in this case is to remove python and recompile it again, linking against the OpenSSL lib. If you downloaded the distribution somewhere else, then its author compiled it without OpenSSL and the distribution is unusable; find another one. – hoefling Jan 16 '19 at 19:34
  • 1
    still, why not just install python3 from apt-get in the Ubuntu vm? – JawguyChooser Jan 16 '19 at 20:44
  • @hoefling How can I link it against OpenSSL? I downloaded the distribution from python.org itself. – handraqui Jan 17 '19 at 00:29
  • @JawguyChooser I didn't realize how could I install exactly Python 3.7.0 through other way than installing from .tar file. I can specify 'sudo apt-get install python3.7', installing 3.7.1, but 'sudo apt-get install python3.7.0' won't work. – handraqui Jan 17 '19 at 00:29
  • I assume it should be sufficient to install the `libssl-dev` package to provide the OpenSSL headers; you should already have the lib itself. After installing, recompile python and verify you have the `ssl` module: `/path/to/custom/python/bin/python -c "import ssl; print(ssl.OPENSSL_VERSION)"`. – hoefling Jan 17 '19 at 00:37
  • Although if you want a more or less complete python distribution, check out [this answer](https://stackoverflow.com/a/45534022/2650249) for a complete list of build dependencies. Should you have any troubles with linking against OpenSSL, check out [this answer on Superuser](https://superuser.com/a/1346305/456335); although it's for the cases where linking against a custom OpenSSL, the commands would be the same, only the paths to include and lib dirs should be adapted. – hoefling Jan 17 '19 at 00:39

1 Answers1

0

I wasn't able to install pandas-datareader. I was getting the same error message. Then, in the CMD window, I just put the command "activate base" and then ran pip again and it worked. I tried with django before and after the "activate base" and if it didn't work before, it did work after. I think it's just some environment variables that are not configured properly. Luckily this will work for you as well. Have a nice day Rémy

  • Thanks for your help! But, unfortunately, it didn't work to me, since I'm using Linux Ubuntu. activate base wasn't recognized as a existent command. – handraqui Jan 18 '19 at 15:44