Published:


Python Permalink

pyenv

Python is a popular programming language used for a wide range of applications, from web development to data analysis. However, managing different Python versions and dependencies across projects can be challenging. This is where pyenv comes in. Pyenv is a powerful tool that allows developers to easily switch between multiple Python versions.

sudo apt-get 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
curl https://pyenv.run | bash

copy to ~/.zshrc.local or ~/.bashrc:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

With pyenv installed, you can now install multiple Python versions. To see the available versions, filtering 3 versions, run:

pyenv install --list | grep " 3"

Choose the desired Python version(s) and install them using the following command:

pyenv install 3.10.9
pyenv install 3.11.1
pyenv versions

By default, pyenv uses the system’s default Python version. To set a global Python version, use the following command:

pyenv global 3.10.9