The way I do it, and it's super effective:
Use pyenv to manage the pyenv versions, and it's plugin pyenv-virtualenv to manage the versions as virtual environments, then poetry to pick the version from them automatically as it manages the dependencies:
Use pyenv to install whatever version of python you want to use:
pyenv install -v 3.7
Create a virtual environment based on the installed version 3.7.
You will need the plugin pyenv-virtualenv.
pyenv virtualenv 3.7 arshbot_3.7_virtualenv
Assume a project called arshbot_proj. Working in $HOME directory:
mkdir ~/arshbot_proj
cd ~/arshbot_proj
Use the virtual env we just created. Attach this project to it.
Below creates .python-version file indicating arshbot_3.7_virtualenv.
pyenv local arshbot_3.7_virtualenv
Use poetry init to create the pyproject.toml inside the dir using
arshbot_3.7_virtualenv.
You could also use poetry new instead of poetry init to create project
structure alongside pyproject.toml instead of making your project first in
above step.
With pyproject.toml and .python-version both inside this dir, poetry
will automatically pick the 3.7 courtesy of arshbot_3.7_virtualenv.
Poetry will also use this virtual env to install packages at
~/.pyenv/versions/3.7/envs/arshbot_3.7_virtualenv/lib/python3.7/site-packages
poetry init
That is it. Poetry will pick the 3.7 automatically every time you run it from inside that directory attached to that virtual environment, with it activated. For different python version, just repeat the above steps, replace 3.7 with the new version.
The virtual environment will appear twice: In the envs directory as a virtual environment, and also in the versions directory as a version, with contents replicating when poetry installs packages.
BONUS:
We try to make it even more clear using a different approach, same concept, same results.
Since by default, if you didn't change PYENV_ROOT, pyenv installs every python version in ~/.pyenv/versions:
If you want the system version(shipped with your distro) to be part of the versions you can select, use venv to mimick a pyenv installation of a python version, now call it system_ver in place of the 3.7. Since it's already in the system, we don't need pyenv to download it, we copy it over to our versions directory, so that it's available to create a virtual environment
cd ~/.pyenv/versions
python3 -m venv --copies system system_ver
pyenv virtualenv system_ver system_ver_virtualenv
To use it in your project in place of previous version 3.7:
cd ~/arshbot_proj
pyenv local system_ver_virtualenv
Poetry will now use whatever version came originally with your distro. The --copies will ensure venv copies the files instead of use links, so you may omit it. Usually useful if you need to later make a multi stage dockerfile for the project using the files from the virtual environment.