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.


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


You can change in pyproject.toml and execute de this command "poetry env use 3.x" that works for me.