Search code examples
pythonpyenv

Zorin OS: Python installation error with pyenv, for 'No module named '_ssl''


I'm having a problem with pyenv, I'm carrying out some tests with the Zorin OS operating system to work with software development. I needed to change the Python version, I installed pyenv. I asked to install a different version of Python than my current version of Zorin OS. I had the error below:

Downloading Python-3.9.18.tar.xz...
-> https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tar.xz
Installing Python-3.9.18...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/eddi/.pyenv/versions/3.9.18/lib/python3.9/ssl.py", line 99, 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 (Zorin 16 using python-build 20180424)

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

Last 10 log lines:
    LD_LIBRARY_PATH=/tmp/python-build.20231102113137.71357/Python-3.9.18 ./python -E -m ensurepip \
        $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpq47gaqxu
Processing /tmp/tmpq47gaqxu/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpq47gaqxu/pip-23.0.1-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.9 are installed in '/home/eddi/.pyenv/versions/3.9.18/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-23.0.1 setuptools-58.1.0

I searched and found this pyenv link, showing some necessary libraries. I performed the installation, restarted the machine, but ended up having a problem with SSL. I looked for a solution again, installed the openssl libssl-dev libs, restarted the machine again. Keep having the same problem.

List of libs I have installed

sudo apt update && sudo apt install build-essential libssl-dev zlib1g-dev \
   libbz2-dev libreadline-dev libsqlite3-dev curl \
   libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev gcc openssl libssl-dev

Solution

  • Try installing those libs

    sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
    

    Then run pyenv install -l to see available versions, and install wanted version.

    Also, if that does not work you can try this command for necessary libs.

    sudo apt-get install build-essential checkinstall 
    sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
    

    Good luck, hope this will help. I would really appreciate some feedback about it :)

    If nothing works you should try reinstalling everything.