Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? #950

Closed
gegewuwuwu opened this issue Jul 17, 2017 · 102 comments
Closed

Comments

@gegewuwuwu
Copy link

➜ ~ pyenv install 3.5.2
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems

BUILD FAILED (Deepin 15.4 using python-build 20160602)

Inspect or clean up the working tree at /tmp/python-build.20170717074120.10900
Results logged to /tmp/python-build.20170717074120.10900.log

Last 10 log lines:
(cd /home/zonzely/.pyenv/versions/3.5.2/share/man/man1; ln -s python3.5.1 python3.1)
if test "xupgrade" != "xno" ; then
case upgrade in
upgrade) ensurepip="--upgrade" ;;
install|*) ensurepip="" ;;
esac;
./python -E -m ensurepip
$ensurepip --root=/ ;
fi
Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS

@aitk
Copy link

aitk commented Jul 19, 2017

What os and version are you using ?

Also the fix is right there in the message you will need to go to https://github.com/pyenv/pyenv/wiki/Common-build-problems#error-the-python-ssl-extension-was-not-compiled-missing-the-openssl-lib then just copy and paste the script for your specific os

@elderone
Copy link

elderone commented Aug 7, 2017

Debian GNU/Linux 9.1 (stretch)
pyenv 1.1.3
CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v 3.2.3

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Debian 9.1 using python-build 20160602)

Inspect or clean up the working tree at /tmp/python-build.20170807132419.25380
Results logged to /tmp/python-build.20170807132419.25380.log

Last 10 log lines:
rm -f /home/elderone/.pyenv/versions/3.2.3/bin/python3-config
(cd /home/elderone/.pyenv/versions/3.2.3/bin; ln -s python3.2-config python3-config)
rm -f /home/elderone/.pyenv/versions/3.2.3/lib/pkgconfig/python3.pc
(cd /home/elderone/.pyenv/versions/3.2.3/lib/pkgconfig; ln -s python-3.2.pc python3.pc)
rm -f /home/elderone/.pyenv/versions/3.2.3/bin/idle3
(cd /home/elderone/.pyenv/versions/3.2.3/bin; ln -s idle3.2 idle3)
rm -f /home/elderone/.pyenv/versions/3.2.3/bin/pydoc3
(cd /home/elderone/.pyenv/versions/3.2.3/bin; ln -s pydoc3.2 pydoc3)
rm -f /home/elderone/.pyenv/versions/3.2.3/bin/2to3
(cd /home/elderone/.pyenv/versions/3.2.3/bin; ln -s 2to3-3.2 2to3)

@elderone
Copy link

elderone commented Aug 7, 2017

building '_ssl' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/openssl -I/home/elderone/.pyenv/versions/3.2.3/include -fPIC -IInclude -I. -I./Include -I/home/elderone/.pyenv/versions/3.2.3/include
 -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/tmp/python-build.20170807132419.25380/Python-3.2.3 -c /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c -o build/temp.linux-x86_64-3.2/tm
p/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.o
In file included from Include/Python.h:111:0,
                 from /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:17:
Include/modsupport.h:27:1: warning: ‘PyArg_ParseTuple’ is an unrecognized format function type [-Wformat=]
 PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);
 ^~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c: In function ‘_create_tuple_for_X509_NAME’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:487:35: error: dereferencing pointer to incomplete type ‘X509_NAME_ENTRY {aka struct X509_name_entry_st}’
             if (rdn_level != entry->set) {
                                   ^~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c: In function ‘_get_peer_alt_names’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:607:16: error: dereferencing pointer to incomplete type ‘X509_EXTENSION {aka struct X509_extension_st}’
         p = ext->value->data;
                ^~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c: In function ‘PySSL_cipher’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:960:21: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     cipher_protocol = SSL_CIPHER_get_version(current);
                     ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c: In function ‘context_new’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1458:9: warning: ‘TLSv1_method’ is deprecated [-Wdeprecated-declarations]
         ctx = SSL_CTX_new(TLSv1_method());
         ^~~
In file included from /usr/include/openssl/ct.h:13:0,
                 from /usr/include/openssl/ssl.h:61,
                 from /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:93:
/usr/include/openssl/ssl.h:1612:1: note: declared here
 DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_method(void)) /* TLSv1.0 */
 ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1465:27: warning: implicit declaration of function ‘SSLv2_method’ [-Wimplicit-function-declaration]
         ctx = SSL_CTX_new(SSLv2_method());
                           ^~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1465:27: warning: passing argument 1 of ‘SSL_CTX_new’ makes pointer from integer without a cast [-Wint-conversion]
In file included from /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:93:0:
/usr/include/openssl/ssl.h:1321:17: note: expected ‘const SSL_METHOD * {aka const struct ssl_method_st *}’ but argument is of type ‘int’
 __owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
                 ^~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c: In function ‘PySSL_RAND_egd’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1924:13: warning: implicit declaration of function ‘RAND_egd’ [-Wimplicit-function-declaration]
     bytes = RAND_egd(PyBytes_AsString(path));
             ^~~~~~~~
At top level:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1974:13: warning: ‘_ssl_thread_locking_function’ defined but not used [-Wunused-function]
 static void _ssl_thread_locking_function
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_ssl.c:1970:22: warning: ‘_ssl_thread_id_function’ defined but not used [-Wunused-function]
 static unsigned long _ssl_thread_id_function (void) {
                      ^~~~~~~~~~~~~~~~~~~~~~~
building '_hashlib' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/openssl -I/home/elderone/.pyenv/versions/3.2.3/include -fPIC -IInclude -I. -I./Include -I/home/elderone/.pyenv/versions/3.2.3/include
 -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/tmp/python-build.20170807132419.25380/Python-3.2.3 -c /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c -o build/temp.linux-x86_6
4-3.2/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.o
In file included from Include/Python.h:111:0,
                 from /tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:16:
Include/modsupport.h:27:1: warning: ‘_PyArg_ParseTuple_SizeT’ is an unrecognized format function type [-Wformat=]
 PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);
 ^~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:62:26: error: field ‘ctx’ has incomplete type
     EVP_MD_CTX           ctx;   /* OpenSSL message digest context */
                          ^~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c: In function ‘EVP_dealloc’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:129:5: warning: implicit declaration of function ‘EVP_MD_CTX_cleanup’ [-Wimplicit-function-declaration]
     EVP_MD_CTX_cleanup(&self->ctx);
     ^~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c: In function ‘EVP_digest’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:165:16: error: storage size of ‘temp_ctx’ isn’t known
     EVP_MD_CTX temp_ctx;
                ^~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:165:16: warning: unused variable ‘temp_ctx’ [-Wunused-variable]
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c: In function ‘EVP_hexdigest’:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:185:16: error: storage size of ‘temp_ctx’ isn’t known
     EVP_MD_CTX temp_ctx;
                ^~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:185:16: warning: unused variable ‘temp_ctx’ [-Wunused-variable]
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c: At top level:
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_md5_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:77:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(md5)
 ^~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_sha1_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:78:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(sha1)
 ^~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_sha224_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:80:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(sha224)
 ^~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_sha256_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:81:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(sha256)
 ^~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_sha384_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:82:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(sha384)
 ^~~~~~~~~~~~~~~~~~~~~
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:74:23: error: storage size of ‘CONST_new_sha512_ctx’ isn’t known
     static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
                       ^
/tmp/python-build.20170807132419.25380/Python-3.2.3/Modules/_hashopenssl.c:83:1: note: in expansion of macro ‘DEFINE_CONSTS_FOR_NEW’
 DEFINE_CONSTS_FOR_NEW(sha512)
 ^~~~~~~~~~~~~~~~~~~~~

Python build finished, but the necessary bits to build these modules were not found:
_dbm               _gdbm                              
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_hashlib           _ssl                               

@elderone
Copy link

elderone commented Aug 8, 2017

CFLAGS="-I/usr/include/x86_64-linux-gnu/" LDFLAGS="-L/usr/lib/x86_64-linux-gnu/" PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.2.3
all the same...

@bosr
Copy link

bosr commented Aug 28, 2017

Hi, look at #945, it's because Debian 9 uses OpenSSL 1.1.0 which support in CPython was added in 3.5.3 (more details in the issue above). Cheers

@dstyp
Copy link

dstyp commented Sep 8, 2017

No solution to this yet? Trying to install...

@bosr
Copy link

bosr commented Sep 8, 2017

@dstyp, are you trying to install a version < 3.5.3? If so I don't know, else the above answers (CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v 3.5.3) should work.

@dstyp
Copy link

dstyp commented Sep 8, 2017

Worked! Thanks, completely overlooked your comment.

@tirtaabimanyu
Copy link

+1 having same trouble installing 3.5.2 on ubuntu

@makslevental
Copy link

i'm having this on mac os high sierra even with setting CFLAGS and LDFLAGS correctly using brew --prefix

@uber1geek
Copy link

uber1geek commented Sep 29, 2017

@makslevental Same here.

Is there a fix available for HighSierra ?

@makslevental
Copy link

@uber1geek the problem turned out to be the openssl hadn't actually successfully installed (even though homebrew reported that it had). run brew uninstall openssl && brew install openssl && CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.2

@colllin
Copy link

colllin commented Sep 29, 2017

I'm using macOS / OSX, but not homebrew, and I'm having this issue as well.

Is there a way to determine...

  1. whether I have openssl installed?

    I tried...

    $ which openssl
    /usr/bin/openssl
    
  2. the correct CFLAGS / LDFLAGS?

    I tried...

    $ CFLAGS="-I/usr/bin/openssl" LDFLAGS="-L/usr/lib" pyenv install 3.6.2
    Downloading readline-6.3.tar.gz...
    -> https://pyenv.github.io/pythons/56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43
    Installing readline-6.3...
    Installed readline-6.3 to /Users/colllin/.pyenv/versions/3.6.2
    
    Downloading Python-3.6.2.tar.xz...
    -> https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
    Installing Python-3.6.2...
    ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
    
    Please consult to the Wiki page to fix the problem.
    https://github.com/pyenv/pyenv/wiki/Common-build-problems
    
    
    BUILD FAILED (OS X 10.13 using python-build 20160602)
    
    Inspect or clean up the working tree at /var/folders/95/rsx7725n60vf4gjk0g9_1h_w0000gn/T/python-build.20170929153257.78102
    Results logged to /var/folders/95/rsx7725n60vf4gjk0g9_1h_w0000gn/T/python-build.20170929153257.78102.log
    
    Last 10 log lines:
    			upgrade) ensurepip="--upgrade" ;; \
    			install|*) ensurepip="" ;; \
    		esac; \
    		 ./python.exe -E -m ensurepip \
    			$ensurepip --root=/ ; \
    	fi
    Collecting setuptools
    Collecting pip
    Installing collected packages: setuptools, pip
    Successfully installed pip-9.0.1 setuptools-28.8.0
    

@makslevental
Copy link

@colllin you need the openssl headers which are in the include dir. i don't know where yours would be

@laenderoliveira
Copy link

I found a solution to my problem. (Fedora 26)
Uninstall:
$ dnf remove openssl-devel

Install:
$ dnf install compat-openssl10-devel

@jlott
Copy link

jlott commented Oct 5, 2017

Mac OS X 10.13 (High Sierra) uses LibreSSL 2.2.7 but doesnt include the C headers necessary to compile the SSL extension for python. I know of no Apple-provided method to get them installed (via XCode or whatever else). To get this working without homebrew or any other shenanigans (assuming you have pyenv installed and working properly);

  • curl -O https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.2.7.tar.gz
  • tar xvf libressl-2.2.7.tar.gz
  • CFLAGS="-I./libressl-2.2.7/include" pyenv install 3.6.3 (or whatever other version)

(post edit)
I believe that pyenv is supposed to install openssl as necessary on Mac OS X in order to make the whole pyenv install process work properly. That is probably the real issue here, but the above steps appear to work around the problem for now.

@matheusabr
Copy link

I tried all suggestions above but it is not working on Hight Sierra 10.13.1 Beta (17B25c) and Xcode 9

@crazyxrp
Copy link

@matheusabr I use @makslevental's method and it works
os version 10.13
installed python version 3.5.4

@matheusabr
Copy link

@crazyxrp It really works! Thanks

@tranvansang
Copy link

tranvansang commented Oct 16, 2017

install openssl-devel.x86_64 or (openssl-dev...) should work.

openssl package only is not enough

Source: https://stackoverflow.com/questions/6171210/building-python-and-more-on-missing-modules

@iartarisi
Copy link

On Debian stretch, installing libssl1.0-dev (and removing libssl-dev) with apt worked fine. Python 2.7 installs fine now.

@jonatanvianna
Copy link

jonatanvianna commented Dec 1, 2017

@laenderoliveira
woked for me

I found a solution to my problem. (Fedora 26)
Uninstall:
$ dnf remove openssl-devel
Install:
$ dnf install compat-openssl10-devel

@Beenhakker
Copy link

In my case (Homebrew, OSX 10.13.1 - High Sierra) I had to specify both CFLAGS and CPPFLAGS:
LDFLAGS="-L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include" CFLAGS="-I/usr/local/opt/openssl/include" pyenv install 3.6.3

@robrem
Copy link

robrem commented Dec 14, 2017

@Beenhakker
Your method worked for me in OSX 10.13.1 for installing 3.6.3. Thanks!

@justinjdickow
Copy link

Not working for me to install 2.7.14 :(

@awper361
Copy link

awper361 commented Jan 5, 2018

Not working for me to install 2.7.6

@Nav31
Copy link

Nav31 commented Jan 16, 2018

@Beenhakker Thanks!
Your solution worked for me as well.

@martimors
Copy link

Had this issue on Ubuntu 22.04 Jammy Jellyfish. The solution was

sudo apt-get update && sudo apt-get install libssl-dev

@janestreeter
Copy link

janestreeter commented May 19, 2022

somewhat of a tangent but in addition to the above sudo apt-get update && sudo apt-get install libssl-dev I also had to do:

sudo apt-get install libbz2-dev libreadline-dev libsqlite3-dev

otherwise I would get errors warnings like

WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?

@dheater
Copy link

dheater commented Jul 1, 2022

Had this issue trying to install Python version3.10.+ on CentOS 7. It's b/c CentOS 7 is still using openssl version 1.0.2k and the python 3.10 series requires openssl-1.1.1+.

@kristofmulier
Copy link

kristofmulier commented Jul 28, 2022

It's my first time using pyenv. I followed this guide to install it:
https://www.liquidweb.com/kb/how-to-install-pyenv-on-ubuntu-18-04/
https://realpython.com/intro-to-pyenv/

Then I ran into the following issue on my Ubuntu 22.04 jammy when attempting to install Python 3.9.13 with pyenv:

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Here is the complete output:

$ pyenv install 3.9.13
Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python curses extension was not compiled. Missing the ncurses lib?
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 22.04 using python-build 2.3.2-10-gff9d3ca6)

Inspect or clean up the working tree at /tmp/python-build.20220728154121.11959
Results logged to /tmp/python-build.20220728154121.11959.log

Last 10 log lines:
	 ./python -E -m ensurepip \
		$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpqhrtnxrs
Processing /tmp/tmpqhrtnxrs/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpqhrtnxrs/pip-22.0.4-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.9 are installed in '/home/kristof/.pyenv/versions/3.9.13/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.0.4 setuptools-58.1.0

Attempting to install python-openssl was useless:

$ sudo apt-get -y install python-openssl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python-openssl

Luckily I found out about libssl-dev:

$ sudo apt -y install libssl-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  chromium-codecs-ffmpeg-extra fonts-font-awesome fonts-lato gstreamer1.0-vaapi
  libgstreamer-plugins-bad1.0-0 libjs-bootstrap4 libjs-highlight.js libjs-lunr
  libjs-modernizr libjs-popper.js libjs-sizzle libva-wayland2 mkdocs node-jquery
  python-babel-localedata python3-argcomplete python3-babel python3-jinja2
  python3-livereload python3-markdown python3-packaging python3-psutil python3-pygments
  python3-pyinotify python3-tornado python3-userpath sphinx-rtd-theme-common
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  libssl-doc
The following NEW packages will be installed:
  libssl-dev
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 2.370 kB of archives.
After this operation, 12,4 MB of additional disk space will be used.
Get:1 http://be.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libssl-dev amd64 3.0.2-0ubuntu1.6 [2.370 kB]
Fetched 2.370 kB in 10s (243 kB/s)                                                           
Selecting previously unselected package libssl-dev:amd64.
(Reading database ... 206635 files and directories currently installed.)
Preparing to unpack .../libssl-dev_3.0.2-0ubuntu1.6_amd64.deb ...
Unpacking libssl-dev:amd64 (3.0.2-0ubuntu1.6) ...
Setting up libssl-dev:amd64 (3.0.2-0ubuntu1.6) ...

Now it works:

$ pyenv install 3.9.13
Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python curses extension was not compiled. Missing the ncurses lib?
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Installed Python-3.9.13 to /home/kristof/.pyenv/versions/3.9.13

To fix the warnings, I did:

$ sudo apt install ncurses-dev
$ sudo apt install libffi-dev
$ sudo apt install libreadline-dev
$ sudo apt install sqlite3 libsqlite3-dev
$ sudo apt install tk-dev

# I tried installing bzip2, but that seems to be ignored when pyenv compiles
# python. I found somewhere that I must then install libbz2-dev instead:
$ sudo apt install bzip2
$ sudo apt install libbz2-dev

# Same problem for lzma. I found that I must install liblzma-dev instead:
$ sudo apt install lzma
$ sudo apt install liblzma-dev

Now it works without warnings:

$ pyenv install 3.9.13
pyenv: /home/kristof/.pyenv/versions/3.9.13 already exists
continue with installation? (y/N) y
Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
Installed Python-3.9.13 to /home/kristof/.pyenv/versions/3.9.13

@native-api
Copy link
Member

@kristofmulier We cannot vouch for the accuracy and completeness of 3rd-party guides. Our README has up-to-date, official installation instructions.

lfit-replication pushed a commit to lfit/ansible-roles-python-install that referenced this issue Aug 29, 2022
- Add new version 3.10.x support.
- Bump 3.8.x, 3.9.x to the latest update.
- Bump the pyenv version to v2.3.3.
- Remove deprecated versions of python:
  (3.4.10, 3.5.10, 3.6.13, 3.7.10)
- Refactor the python-install role to address 'line too
   long' error while building the pyenv command.
- Install compact-openssl10 dependencies for python 3.10
  ERROR: The Python ssl extension was not compiled. Missing the
  OpenSSL lib?
  The compat-openssl libs are available only for CentOS8, so python
  3.10x will be available for >= CentOS8.
- Include libssl-dev required for building Ubuntu {18,20}.04

Issue-ID: RELENG-4357
Ref: pyenv/pyenv#950
Change-Id: I3fe4fed872a43bf21a07fefc6c161b143f306ca2
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
@dgharsallah
Copy link

Ubuntu 20.04

  1. Edit this file /etc/apt/sources.list and add this line to the end of it.
    deb http://security.ubuntu.com/ubuntu bionic-security main
  2. sudo apt update && apt-cache policy libssl1.0-dev
  3. sudo apt-get install libssl1.0-dev

Thanks a lot man!! Been struggling to install python 3.2 on Ubuntu 22.04 until I found your post!
Thanks again really!

@brad-hajek
Copy link

On Amazon Linux 2, pyenv install -v 3.10.x required removing openssl-devel and installing openssl11-devel instead:

sudo yum remove openssl-devel
sudo yum install openssl11-devel

@ladyrick
Copy link

ladyrick commented Dec 15, 2022

After all the efforts, I find that use a self-compiled openssl is the easiest way to solve.
On some old versions of debian (or other release), the openssl is not new enough to meet a newer python version's requirement, even you apt upgrade-d it.

Here is my script:

#!/bin/bash

cd ~/.pyenv
mkdir build
cd build

# download a latest version of openssl
wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz.sha256
wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz

# do check sha256 before compile it
sha256sum openssl-1.1.1s.tar.gz

tar xf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s

# compile
./config no-shared  # MUST use `no-shared` config, or you will always need LD_LIBRARY_PATH env
make -j32
make test

cd ~/.pyenv/build/openssl-1.1.1s
CFLAGS=-I$(pwd)/include LDFLAGS=-L$(pwd) ~/.pyenv/bin/pyenv install 3.11.1

Now everything works.

@Trinkle23897
Copy link

Hey @ladyrick, that's super useful information! However, when I tried to build py3.11 on ubuntu 16.04, it still hit the missing openssl lib error. But it went success while building 3.7/8/9/10 on ubuntu 16.04:

Installing collected packages: setuptools, pip
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/root/.pyenv/versions/3.11-dev/lib/python3.11/ssl.py", line 100, in <module>
    import _ssl             # if we can't import it, let the error propagate
    ^^^^^^^^^^^
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 16.04 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20221227050241.86
Results logged to /tmp/python-build.20221227050241.86.log

I'm not sure what happened, can anyone help take a look? Thanks in advance!

@ladyrick
Copy link

Hey @ladyrick, that's super useful information! However, when I tried to build py3.11 on ubuntu 16.04, it still hit the missing openssl lib error. But it went success while building 3.7/8/9/10 on ubuntu 16.04:

Installing collected packages: setuptools, pip
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/root/.pyenv/versions/3.11-dev/lib/python3.11/ssl.py", line 100, in <module>
    import _ssl             # if we can't import it, let the error propagate
    ^^^^^^^^^^^
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 16.04 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20221227050241.86
Results logged to /tmp/python-build.20221227050241.86.log

I'm not sure what happened, can anyone help take a look? Thanks in advance!

maybe upgrade your pyenv and install 3.11.1 instead?

@Trinkle23897
Copy link

Thanks for reply! This issue constantly exists and I'm able to use docker to reproduce it:

FROM ubuntu:16.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ENV PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH

WORKDIR $HOME

# install base dependencies

RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test

RUN apt-get update \
    && apt-get install -y curl wget build-essential make git

RUN curl https://pyenv.run | sh

# install newest openssl (for py3.10 and py3.11)

RUN wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
RUN tar xf openssl-1.1.1s.tar.gz
WORKDIR $HOME/openssl-1.1.1s
RUN ./config no-shared
RUN make -j
RUN make install

# install python

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> /etc/profile
RUN echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> /etc/profile
RUN echo 'eval "$(pyenv init -)"' >> /etc/profile

RUN apt-get install -y zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev libncursesw5-dev libffi-dev

RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.11.1
#RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.10-dev
#RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.9-dev
#RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.8-dev
#RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.7-dev

The command to run is docker build --network=host -f test.dockerfile .. You'll see the same error. Therefore it's neither old-version pyenv issue nor 3.11.1 issue.

@Trinkle23897
Copy link

Trinkle23897 commented Dec 28, 2022

Hah, py3.11+ubuntu1604 is somewhat special: You need to use ./configure instead of ./configure no-shared to build libssl.so.1.1, otherwise py311 won't find this shared library and won't build _ssl module.
(Note: you'll see the following in the log and that's the exact reason:)

*** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.1: cannot open shared object file: No such file or directory             
*** WARNING: renaming "_hashlib" since importing it failed: libcrypto.so.1.1: cannot open shared object file: No such file or directory      

This dockerfile works:

FROM ubuntu:16.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ENV PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH

WORKDIR $HOME

# install base dependencies

RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test

RUN apt-get update \
    && apt-get install -y curl wget build-essential make git

RUN curl https://pyenv.run | sh

# install newest openssl (for py3.10 and py3.11)

RUN wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
RUN tar xf openssl-1.1.1s.tar.gz
WORKDIR $HOME/openssl-1.1.1s
RUN ./config
RUN make -j
RUN make install

# install python

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> /etc/profile
RUN echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> /etc/profile
RUN echo 'eval "$(pyenv init -)"' >> /etc/profile

RUN apt-get install -y zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev libncursesw5-dev libffi-dev
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.11-dev

@stephen-a2z
Copy link

stephen-a2z commented Mar 7, 2023

the following command fixed my case, maybe it's helpful to you. My pyenv version is '2.3.14-3-g6052caa0'

env PYTHON_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" pyenv install -v <your-python-version>

@doradsoft
Copy link

Hah, py3.11+ubuntu1604 is somewhat special: You need to use ./configure instead of ./configure no-shared to build libssl.so.1.1, otherwise py311 won't find this shared library and won't build _ssl module. (Note: you'll see the following in the log and that's the exact reason:)

*** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.1: cannot open shared object file: No such file or directory             
*** WARNING: renaming "_hashlib" since importing it failed: libcrypto.so.1.1: cannot open shared object file: No such file or directory      

This dockerfile works:

FROM ubuntu:16.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ENV PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH

WORKDIR $HOME

# install base dependencies

RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test

RUN apt-get update \
    && apt-get install -y curl wget build-essential make git

RUN curl https://pyenv.run | sh

# install newest openssl (for py3.10 and py3.11)

RUN wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
RUN tar xf openssl-1.1.1s.tar.gz
WORKDIR $HOME/openssl-1.1.1s
RUN ./config
RUN make -j
RUN make install

# install python

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> /etc/profile
RUN echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> /etc/profile
RUN echo 'eval "$(pyenv init -)"' >> /etc/profile

RUN apt-get install -y zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev libncursesw5-dev libffi-dev
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.11-dev

Do not forget to WORKDIR /

@native-api
Copy link
Member

native-api commented May 8, 2023

@RobYang203
Copy link

the following command fixed my case , thank you very much

@imRP26
Copy link

imRP26 commented Aug 8, 2023

brew uninstall openssl && brew install openssl && CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.2

I faced a similar issue with openssl and used this hack to install python 3.9.17 using pyenv on my MAC 13.4.1. Thanks!

@darth-veitcher
Copy link

Running on linux (Pop_OS) the following one-liner fixed my install issues with 3.10.13, imagine it will work for other ubuntu / apt style distros.

sudo apt install --no-install-recommends \
  libssl-dev \
  ncurses-dev \
  libffi-dev \
  libreadline-dev \
  sqlite3 libsqlite3-dev \
  tk-dev \
  bzip2 libbz2-dev \
  lzma liblzma-dev

@qeleb
Copy link

qeleb commented Oct 18, 2023

Make sure to use openssl@1.1 rather than putting openssl or openssl@3 if you are installing Python <3 (like 2.7.18)

If you are using brew, add this to .zshrc/.bashrc for installing Python <3:

export LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib -L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix ncurses)/lib -L$(xcrun --show-sdk-path)/usr/lib"
export CFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix openssl@1.1)/include -I$(brew --prefix readline)/include -I$(brew --prefix ncurses)/include -I$(xcrun --show-sdk-path)/usr/include"
export CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix openssl@1.1)/include -I$(brew --prefix readline)/include -I$(brew --prefix ncurses)/include -I$(xcrun --show-sdk-path)/usr/include"

If you are using brew, add this to .zshrc/.bashrc for installing Python >=3:

export LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix ncurses)/lib -L$(xcrun --show-sdk-path)/usr/lib"
export CFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix openssl)/include -I$(brew --prefix readline)/include -I$(brew --prefix ncurses)/include -I$(xcrun --show-sdk-path)/usr/include"
export CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix openssl)/include -I$(brew --prefix readline)/include -I$(brew --prefix ncurses)/include -I$(xcrun --show-sdk-path)/usr/include"

@Nghiauet
Copy link

Turn out I haven't install openssl

@tigerhawkvok tigerhawkvok mentioned this issue Jan 30, 2024
5 tasks
@emad-aldeen
Copy link

if you are trying to install python3.10+ by pyenv and you are in Ubuntu 20.04.6 and your OpenSSL is installed by linuxbrew..
you need to use openssl@1.1 by brew install openssl@1.1
then will see a message after successful installation

For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/openssl@1.1/lib" export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/openssl@1.1/include"

export those 2 vars then use PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.1 pyenv install 3.10 to install your python

@Extibax
Copy link

Extibax commented Feb 9, 2024

Running on linux (Pop_OS) the following one-liner fixed my install issues with 3.10.13, imagine it will work for other ubuntu / apt style distros.

sudo apt install --no-install-recommends \
  libssl-dev \
  ncurses-dev \
  libffi-dev \
  libreadline-dev \
  sqlite3 libsqlite3-dev \
  tk-dev \
  bzip2 libbz2-dev \
  lzma liblzma-dev

ty so much, so helpful on elementary os also

@trevorpfiz
Copy link

if you are trying to install python3.10+ by pyenv and you are in Ubuntu 20.04.6 and your OpenSSL is installed by linuxbrew.. you need to use openssl@1.1 by brew install openssl@1.1 then will see a message after successful installation

For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/openssl@1.1/lib" export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/openssl@1.1/include"

export those 2 vars then use PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.1 pyenv install 3.10 to install your python

thank you for this, but it does not seem to work for pyenv install 3.11.

@qaziqarta
Copy link

For platforms that don't have an option to upgrade to OpenSSL 1.1.1+ (e.g. Debian 8, that has OpenSSL up to only 1.1.0 in standard package repo), you can build custom OpenSSL and build Python against that:

  1. Install OpenSSL 1.1.1+ as described here and here. E.g.:
curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz
tar xzf openssl-VERSION.tar.gz
cd openssl-VERSION
./config \
    --prefix=/usr/local/custom-openssl \
    --libdir=lib \
    --openssldir=$(find /etc/ -name openssl.cnf -quit -printf "%h" 2>/dev/null)
make -j1 depend
make -j8
make install_sw
cd -

openssldir and install_sw is important if you don't want to override your current openssl.cnf.
2. Run pyenv with:
env PYTHON_CONFIGURE_OPTS="--with-openssl=/usr/local/custom-openssl --with-openssl-rpath=auto" pyenv install -v <your-python-version>

@chenbt-hz
Copy link

I used Rocky Linux 9.3 ,and got two diff openssl :

>find /usr -name openssl.pc 
/usr/lib64/pkgconfig/openssl.pc
/usr/local/lib64/pkgconfig/openssl.pc

but pkg-config --cflags openssl get nothing
Finally fix with the right directory:

CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib64" pyenv install -v  3.7.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests