DEV Community

milktea02
milktea02

Posted on • Edited on

struggle tweets to install python 3.10.2 with pyenv on Ubuntu 20.04 (WSL)

If you want to watch me struggle, continue below. Otherwise just go here: https://computingforgeeks.com/how-to-install-python-on-ubuntu-linux-system/

I just bought a new laptop and figured, setting up my WSL Ubuntu environment should be pretty straightforward right? All I need to do is git clone a few repos and setup my $PATH.

I was very wrong.

I'm not an expert in setting up Linux environments and it just so happened that Stackoverflow was going through some things (https://twitter.com/StackStatus/status/1502788125285879817).

Anyway, some of the things I needed to get my pyenv v2.2.4 to even install python v3.10.2

At this point I've already apt install the following:



gcc
make
build-essential


Enter fullscreen mode Exit fullscreen mode

but I'm still getting the following error:



$ pyenv install 3.10.2
Downloading Python-3.10.2.tar.xz...
-> https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
Installing Python-3.10.2...

BUILD FAILED (Ubuntu 20.04 using python-build 2.2.4)

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

Last 10 log lines:
  File "/tmp/python-build.20220312160907.27360/Python-3.10.2/Lib/ensurepip/__init__.py", line 277, in _main
    return _bootstrap(
  File "/tmp/python-build.20220312160907.27360/Python-3.10.2/Lib/ensurepip/__init__.py", line 193, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
  File "/tmp/python-build.20220312160907.27360/Python-3.10.2/Lib/ensurepip/__init__.py", line 93, in _run_pip
    return subprocess.run([sys.executable, '-W', 'ignore::DeprecationWarning',
  File "/tmp/python-build.20220312160907.27360/Python-3.10.2/Lib/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20220312160907.27360/Python-3.10.2/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpbfu6lr32/setuptools-58.1.0-py3-none-any.whl\', \'/tmp/tmpbfu6lr32/pip-21.2.4-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpbfu6lr32\', \'--root\', \'/\', \'--upgrade\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:1280: install] Error 1


Enter fullscreen mode Exit fullscreen mode

Looking at the logs provided, indeed I am missing a lott of tools:



$ cat /tmp/python-build.20220312160907.27360.log | grep -e "hecking.*no$" | wc -l
197


Enter fullscreen mode Exit fullscreen mode

I'm just looking blindly through and find the following:



ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 618, in _get_data
  File "<frozen zipimport>", line 573, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available


Enter fullscreen mode Exit fullscreen mode


The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel
_dbm                  _gdbm                 _hashlib
_lzma                 _sqlite3              _ssl
_tkinter              _uuid                 readline
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time


Failed to build these modules:
_ctypes


Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer


Enter fullscreen mode Exit fullscreen mode

okay, what is zlib? https://packages.ubuntu.com/source/focal/zlib

Not too helpful, as there are a bunch of different packages here that I can install, but which one?

Image screen snippet of the ubuntu packages search for zlib which shows several zlib packages

The internet seems to say zlib1g-dev.

So I suppose I'll need to get the dev versions of all these C library packages:



zlib1g-dev
libbz2-dev
libsqlite3-dev
libgdbm-dev
libssl-dev
libncurses5-dev
libreadline-dev
liblzma-dev


Enter fullscreen mode Exit fullscreen mode

Anyway, since I know nothing and am just meandering through this on my own even though I can copy paste the list of dependencies someone else has posted on the internet, I decide to only install zlib1g-dev since the other ones are required for optional modules (which I'll probably need later and regret not installing now).

Okay so what happens when I try to pyenv install 3.10.2 now?



$ pyenv install 3.10.2
Downloading Python-3.10.2.tar.xz...
-> https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
Installing Python-3.10.2...
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?
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 20.04 using python-build 2.2.4)

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

Last 10 log lines:
Installing collected packages: setuptools, pip
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /home/banana/.pyenv/versions/3.10.2/include/python3.10/setuptools
  sysconfig: /tmp/python-build.20220312165507.7502/Python-3.10.2/Include/setuptools
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /home/banana/.pyenv/versions/3.10.2/include/python3.10/pip
  sysconfig: /tmp/python-build.20220312165507.7502/Python-3.10.2/Include/pip
  WARNING: The scripts pip3 and pip3.10 are installed in '/home/banana/.pyenv/versions/3.10.2/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-21.2.4 setuptools-58.1.0


Enter fullscreen mode Exit fullscreen mode

Okay that seems like a more positive step. The only error that I see now is that ssl extensions was not compiled. Seems important. Let's install libssl-dev

Okay AGAIN:



Downloading Python-3.10.2.tar.xz...
-> https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
Installing Python-3.10.2...

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?
Installed Python-3.10.2 to /home/banana/.pyenv/versions/3.10.2


Enter fullscreen mode Exit fullscreen mode

YAY!



$ pyenv versions
* system (set by /home/banana/.pyenv/version)
  3.10.2


Enter fullscreen mode Exit fullscreen mode

We'll ignore all the warnings... until next time.

Top comments (0)