2

Situation

Our company has an internal Server

  • OpenSUSE Leap 15.5
  • Python 3.6(.15)
  • Python 2.7(.18)

see details for more information

Task

As Python 3.6 is already EOL we want to install a newer Python (3.10 or 3.11).
In order to not break anything I would like to

  1. install the new python in parallel
  2. install it additionally (not replacing or breaking any of the existing installations or aliasses)
  3. have it available from anywhere (scripts)

As this Server is vital to our development process, I would like to go for the lowest risk possible.

Questions

  1. How risky is installing another python with regards to system stability, the other python installations and the "python" binary/symlink?
  2. How should I install python in a lowest-risk-manner?

Details

***:~> cat /etc/os-release
NAME="openSUSE Leap"
VERSION="15.5"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.5"
PRETTY_NAME="openSUSE Leap 15.5"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.5"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
LOGO="distributor-logo-Leap"


***:~> zypper info python
...
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : python
Version        : 2.7.18-150000.51.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 1.4 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : python-2.7.18-150000.51.1.src
Upstream URL   : https://www.python.org/
Summary        : Python Interpreter
...

***:~> zypper info python3
...
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : python3
Version        : 3.6.15-150300.10.48.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 141.3 KiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : python3-3.6.15-150300.10.48.1.src
Upstream URL   : https://www.python.org/
Summary        : Python 3 Interpreter
....

1 Answer 1

2

This solution is for openSUSE only. Although you could use them for SUSE Linux Enterprise Server too, it's currently not supported. Use it at your own risk!

You could try pyenv, that allows to use different Python versions for a specific user. I use it for many months now and I'm pretty happy with it.

I'm not sure if this would be allowed by your policies. However, this solution would be something with minimal impact or disruption to your system. You don't have to mangle your system.

Keep in mind, this will only work for a specific user. Other users won't see this change and are not affected. This may or may not be an advantage.

Preparing the system

Before you can use a specific Python version, you need to install and configure pyenv.

Proceed as follows:

  1. Integrate the devel:languages:python:backports repo into your system.

  2. Install the pyenv package:

     $ sudo zypper install --details pyenv
    
  3. Install the following devel packages that are needed to build Python:

     $ sudo zypper install -y gcc automake bzip2 libbz2-devel \
       xz xz-devel openssl-devel ncurses-devel readline-devel \
       zlib-devel tk-devel libffi-devel sqlite3-devel \
       gdbm-devel make findutils patch
    
  4. Add the following lines to your ~/.bashrc file:

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

    If you use another shell, refer to https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv

  5. Restart your shell with exec $SHELL or close your console and open a new one.

Install a different Python version

Your system is ready now. The pyenv command downloads the requested version, compiles it and stores it under ~/.pyenv/versions/. Once this is done, you can use your new Python version in the shell.

To install a specific Python version, proceed as follows:

  1. Install a Python version, for example 3.11:

     $ pyenv install 3.11
    
  2. Set this version for your specific user:

     $ pyenv global 3.11
    

    If you want to restrict it to your current directories, use:

     $ pyenv local 3.11
    
  3. Check if pip3 resolves to the local installation:

     $ pip3.11 --version
     pip 23.1.2 from /home/tux/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pip (python 3.11)
    

    You should see a directory that points to the user, not starting with /usr/.

After you prepared your systems, pyenv allows you to install any Python library into your local installation. For example:

$ pip3.11 install <LIBRARY>

Closing remarks

Keep in mind, this method circumvents the RPM system and zypper. You don't get any updates from them. However, if you need a newer Python version, you need to update the pyenv package to gain access to the latest versions.

Additionally, you need to be careful about Python version coming from a RPM. You might get confused as there are similar names (pip3.11 vs. pip3-3.11).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.