Trying to install packages with Python 3.7.2 pip causes TSL/SSL errors

房东的猫 提交于 2019-12-05 05:20:22

So, SSLError("Can't connect to HTTPS URL because the SSL module is not available.") in this context indicates that when you compiled python3.7 from sources, it wasn't linked against your system OpenSSL library. The pedantic solution would be to ensure you have the required headers besides the lib, with something like:
$ yum install openssl-devel.x86_64 openssl.x86_64
and recompile from scratch, linking against the OpenSSL lib.

However, as you have rightly noted, installing python3 with yum (from Amazon's own repo, packages tested for Amazon Linux) is way easier and more robust approach in EC2, and will resolve all dependencies. For example, something like this is going to work in Amazon Linux (version 1):

$ yum install python36.x86_64
$ yum install python36-pip.noarch

Usually, Python3.6 is already pre-installed in EC2, but not python36-pip...

This is correct and default behavior that Python3's pip script is called by pip3 command, while pip is for Python2 (if installed - the yum package for python2 is python27-pip.noarch), for example:

$ pip3 -V  
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)  
$ pip2 -V  
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)  
$ pip -V  
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)  

There are also versioned Python commands available in combination with the -m switch (for module) to run corresponding version of pip, for example:
$ python3 -m pip install --user flask

The one you installed via get-pip.py --user has likely landed somewhere in your $HOME/.local/bin directory. The --user switch installs packages just for the current user (in ~/.local/lib/) rather than for the whole system, which is actually a good practice to avoid interfering with the system python packages.

Even better, you could use pip inside a virtualenv or venv isolated environments: there is the python36-virtualenv (installable via yum), and the default 'venv' module built-in Python3 and readily available (python3 -m venv yournewenvname). Once you create and then activate your isolated python environment (a directory), you can just do a simple pip install flask there regardless of python version. Good luck!

You can ignore the ssl error or install the open-ssl. You should try this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!