pyenv is a popular command-line tool that helps Python developers manage multiple Python versions efficiently. If you work on various Python projects, each requiring a different version of Python, pyenv keeps your workflow smooth by allowing you to install, switch, and manage Python versions effortlessly.
https://github.com/pyenv/pyenv
To install, run
curl -fsSL https://pyenv.run | bash
Edit ~/.profile
vi ~/.profile
add at the end of the file
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"
Install build dependency
on Ubunutu, run
apt update; apt install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
For other operating systems, see
https://github.com/pyenv/pyenv/wiki#suggested-build-environment
Install a specific Python version
pyenv install 3.12.3
To swich python version
pyenv shell 3.12.3
Once you are inside shell, you can create virtual environment as needed.
To find file location, run
pyenv which python3.12
Set the global Python version:
pyenv global 3.12.3
Set a local version for a project:
pyenv local 3.12.3
To list all installed python versions, run:
pyenv versions
Back to Python
Leave a Reply