poetry change python version to 3.x poetry change python version to 3.x python python

poetry change python version to 3.x


Whenever you change dependencies by hand in your pyproject.toml you have to take care of these points:

  1. Run poetry lock afterwards or remove the poetry.lock file to force recreation of it. The reasons for this is, that poetry install takes the poetry.lock as input if can find one and not the pyproject.toml.

  2. If you change the python version and uses in-project virtualenv, remove the .venv before running poetry install. poetry doesn't change the python version of a venv once it is created, because it uses the python version itself to create the virtualenv.


Poetry makes it super easy to work with different Python versions or virtual environments. The recommended way to specify your Python version according to Poetry docs is

poetry env use /path/to/preferred/python/version

You can get the path to your Python version by running

which python3.7


I had the same problem. I solve it by fixing the first line in the file /home/nordman/.poetry/bin/poetry (nordman is my local name).

Just change #!/usr/bin/env python to #!/usr/bin/env python3