This guide will be a short introduction how you can install pyenv and Poetry then use that to switch python environments locally.
pyenv lets you easily switch between multiple versions of Python.
You will need sudo permissions to download certain packages for the install to work:
sudo apt-get install -y build-essential
libbz2-dev libncursesw5-dev libreadline-dev libffi-dev libssl-dev
libgdbm-dev zlib1g-dev libsqlite3-dev liblzma-dev tk-dev uuid-devafter that you can just run the below commands to get your pyenv working on your account without sudo:
curl https://pyenv.run | bashCheck out pyenv github page for what you need to export to get it working in your terminal for my set up in Ubuntu I ran:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init - bash)"' >> ~/.bashrcThen refresh your terminal and check it has installed
source ~/.bashrc
pyenv --versionTo install Poetry it is recommend to have pipx installed and follow the poetry guidelines here(https://python-poetry.org/docs/)
Once you have a repo set up with your desired python version you can use pyenv with Poetry to change python versions locally:
pyenv install 3.9.8
pyenv local 3.9.8 # Activate Python 3.9 for the current project
poetry install