Sobes.tech
Middle

How to install a different version of Python from the system version in Astra OS?

sobes.tech AI

Answer from AI

Astra Linux is based on Debian, so the approaches are similar. The best way is to use pyenv.

  1. Installing dependencies:
# Update package list
sudo apt update
# Install necessary dependencies for building Python
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-1.7 libbz2-dev libreadline-dev libsqlite3-dev wget curl \
llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
libffi-dev liblzma-dev openssl
  1. Installing pyenv:
# Download the pyenv-installer script
curl https://pyenv.run | bash
  1. Configuring the environment:

Add the following lines to your .bashrc (or .zshrc if you use zsh):

# pyenv configuration
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Apply the changes:

source ~/.bashrc
  1. Installing the desired Python version:
# List available versions
pyenv install --list
# Install the chosen version, e.g., 3.10.0
pyenv install 3.10.0
  1. Selecting the Python version:
  • Globally (for the entire system):
pyenv global 3.10.0
  • Locally (for a specific directory): Navigate to the project directory.
pyenv local 3.10.0
  1. Verification:
python --version

Now, the python command will use the version you installed. The system Python remains accessible via /usr/bin/python or /usr/bin/python3.