GNU/Linux >> Linux Esercitazione >  >> Linux

Come compilare e installare Python con il supporto di OpenSSL?

La tua installazione di Python non supporta SSL? Devi compilarlo di nuovo dopo aver modificato Setup.dist file che si trova nella directory di origine di Python. Vediamo come farlo.

Prima di iniziare, controlla se la tua installazione Python esistente supporta OpenSSL come mostrato di seguito:

$ python

Nel prompt di Python, digita "import ssl"

>>> import ssl

Se vedi un errore come di seguito, Python non supporta SSL.

$ python
Python 2.4.3 (#1, Jan 9 2013, 06:47:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
ImportError: No module named ssl
>>>

Nota: Nelle versioni precedenti di Python, puoi provare a usare "hasattr ' come mostrato di seguito:

>>> import socket
>>> hasattr(socket,"SSL")
False
>>>

Se vedi "Falso “, Python non supporta SSL.

Come compilare Python dal sorgente con il supporto di OpenSSL

Prerequisiti:

OpenSSL dovrebbe essere installato per impostazione predefinita, ma se non ne hai uno, installalo come mostrato di seguito.

Installa OpenSSL e i suoi pacchetti di sviluppo come di seguito:

$ yum install openssl
$ yum install openssl-devel

(o)

Installa OpenSSL dal sorgente:

$ wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz
$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl

Nota: Per impostazione predefinita openssl verrà installato in /usr/local/ssl . Se non vuoi rovinare l'installazione SSL esistente, installala in una directory diversa.

$ make
$ make test
$ make install

L'installazione di OpenSSL è completata. Ora compiliamo Python.

Scarica sorgente Python:

$wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
$tar xvzf Python-3.5.1.tgz
$vim Modules/Setup.dist

Cerca "SSL ” e decommentare il codice come mostrato di seguito (nella versione 3.5, dalla riga 203 alla 210):

_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
 -L$(SSL)/lib -lssl -lcrypto

Nota: Nel caso, se hai installato OpenSSL in una posizione non standard, devi cambiare "SSL ' per fare riferimento al percorso corretto nel codice sopra.

Ad esempio,

_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/openssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

Una volta fatto,

$ ./configure
$ make
$ make install

Controlla Python per il supporto OpenSSL

$/usr/local/bin/python3.5

Nel prompt di Python, digita "import ssl

>>> import ssl

Se non vedi alcun errore, Python supporta SSL. Ecco fatto!


Linux
  1. Come installare Python 2 e Python 3 su Fedora 35

  2. Come installare Python su Ubuntu 20.04 e 18.04?

  3. Come installare Elasticsearch su Ubuntu 22.04 con SSL

  4. Come installare Apache 2 con SSL su Linux (con mod_ssl, openssl)

  5. Come compilare il file .c con OpenSSL include?

Come installare Flask con Python 3 su Ubuntu 18.04

Come installare Python 2 e Python 3 su CentOS 8

Come installare FTP con SSL in Rocky Linux e AlmaLinux

Come installare Python 2.7 su CentOS 7.1 o 6.7 con Anaconda

Come installare Apache con Python Mod_wsgi su Debian 10

Come installare e configurare WordPress con Ansible