J2897 icon

Installing Multiple Python Versions on Debian

J2897 | PRO | 09/08/24 03:26:55 PM UTC (Edited) | 0 ⭐ | 679 👁️ | Never ⏰ | []
Markdown |

3.15 KB

|

None

|

0 👍

/

0 👎


Install dependencies for pyenv:
sudo apt update
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev \
libffi-dev liblzma-dev python3-openssl git


Install pyenv:
curl https://pyenv.run | bash


Update your shell configuration to include pyenv in your PATH. Add the following lines to ~/.bashrc or ~/.bash_profile:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"


Restart your shell:
exec $SHELL


Install different versions of Python using pyenv:
pyenv install 3.9.19
pyenv install 3.12.5


Set the global or local Python version:

To set the global default version:
pyenv global 3.12.5
To set a local version (specific to a directory/project):
pyenv local 3.9.19  # Generates a '.python-version' file



Run a specific version of Python:
pyenv shell 3.9.19  # Temporarily use Python 3.9.19


Run a script with Python 3.9.19 without changing the global or local version:
pyenv shell 3.9.19 && python your_script.py


Show all available versions. Similar to py -0 on Windows:
pyenv versions

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎