I have compiled and installed Python 3.7 on my Raspberry Pi, but SSL is not working.
These are the steps I took to install the new Python:
Prerequisites:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade
$ sudo apt-get install build-essential checkinstall python-dev python-setuptools python-pip python-smbus
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libgdbm-dev libc6-dev libbz2-dev
$ sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
$ sudo apt-get install libssl-dev openssl
$ sudo apt-get install libffi-dev
Download and extract Python 3.7:
$ cd /usr/src
$ sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
$ sudo sudo tar xzf Python-3.7.0.tgz
Configure and compile:
$ cd Python-3.7.0
$ sudo -s
# bash configure
# make altinstall
# exit
Make Python 3.7 the default:
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.4 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
$ sudo update-alternatives --config python3
It wasn't until I had already gone through this that I realized SSL was missing, when I went to install something with pip
.
$ pip3 install --upgrade python-osc
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting python-osc
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.")': /packages/9c/2c/72e50535fa41b703ee891b6d06c661ad4d1c973992a7f09686ac8bb4cef6/python-osc-1.6.8.tar.gz
(...)
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/9c/2c/72e50535fa41b703ee891b6d06c661ad4d1c973992a7f09686ac8bb4cef6/python-osc-1.6.8.tar.gz (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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
I saw in some other questions like this that perhaps libssl
was not installed, but I did install libssl-dev
with apt-get
, as you see above.
I scrolled back to my configure
output and saw this:
...
checking for pkg-config... /usr/bin/pkg-config
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... no
checking for --with-ssl-default-suites... python
That third line, checking for X509_VERIFY_PARAM_set1_host
being no
seems to be a bad indicator.
When running make
, I see these errors related to SSL:
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_ssl _uuid
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
...
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
So, I thought I did all of the right things and had the most recent libssl
installed, but Python is still not seeing it. How can I get Python 3.7 to build with SSL?
EDIT: I am on Raspbian GNU/Linux 8 (jessie), if that makes a difference. Would it help if I upgraded to Stretch?
UPDATE: Not sure why this is being marked as off-topic, because the problems I had installing Python 3.7 seem rather specific to Raspbian. I did upgrade the Raspberry Pi to Stretch, and then I was able to install Python 3.7 without these SSL errors. However, once Python 3.7 is installed on the Raspberry Pi, it breaks so many other things in Python 3 on the Pi, that it doesn't seem worth it. I ended up doing a clean install of Raspbian Stretch, and just using the included Python 3.5.3, which presented fewer problems.
python-openssl
? – Dmitry Grigoryev Aug 16 '18 at 09:18python-openssl
just gives easier access to the OpenSSL library functions. The_ssl
module still needs to be built for that to work. Thanks, though. – swizzlevixen Aug 16 '18 at 17:40libssl
in order to compile with SSL support. If you want to install Python 3.7 on Jessie with SSL, you need to compile a local version ofopenssl
first and link to that when compiling Python itself. See this answer. Stretch is fine in that regard. – Rafa Viotti Oct 17 '18 at 19:45