Keep One Version of Python on Your System Without Pyenv

Recently, Deezer decided not to maintain the open-source Spleeter Python package in favor of their new spleeter pro product. If you recall, I utilized Spleeter in one of my scripts. Due to its lack of maintenance, it caused dependency issues as my Python system version continuously updated. To resolve this, I initially installed the correct version using pyenv and set up my virtual environment (venv). I never used pyenv before and using it only for creating a venv for spleeter annoyed me so i'm going to quickly show you how to build python from source and install it separately from your system one.

  1. Download the version you want here. For my spleeter issue the right version is the latest Python 3.10.
  2. Extract it somewhere and open a terminal in the extracted folder.
  3. Ensure you have the bare minimum to compile and the dependencies.
  4. Choose a location, I like to keep my python version in /opt/, then you launch : ./configure --enable-optimizations --prefix=/opt/python-3.10
  5. Then you build by typing make.
  6. mkdir the prefix folder, check your rights to write in your prefix folder, set them with chmod and chown.
  7. Then to install you type make install.
  8. Create your new virtualenv with your freshly compiled python by invoking /opt/python-3.10/bin/python3 -m venv /somewhere/for/the/venv.
  9. Finally you can source the venv/bin/activate.

This method works well if you want just one or two version of python, if you have multiple and must switch to several venv often look at some tools like pyenv and virtualenvwrapper.