Poetry uses wrong Python version
See original GitHub issue- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- OS version and name: Linux Mint 20.1
- Poetry version: 1.1.6
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/joooeey/78317c68c58d8aaa2d452c02212031f3
Issue
We’re developing a project on a few machines with several different Python versions installed. We’re using Poetry to make sure we have the same development environment. But unfortunately Poetry doesn’t check if the right Python version is installed. I expect to get an error or a warning if Poetry isn’t running on the Python version specified in the pyproject.toml
file (Python 3.9). But Poetry lets this slip, so when working on my laptop the other day I only got a failure at runtime when suddenly tons of errors with type annotation popped up. It took me a while to figure out this was because I was using an old Python version (3.8).
To reproduce, copy the pyproject.toml
linked above and run the following commands:
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry install
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry run python
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry env info
Virtualenv
Python: 3.8.5
Implementation: CPython
Path: /home/lukas/.cache/pypoetry/virtualenvs/edeo-sensing-iAOxxtc0-py3.8
Valid: True
System
Platform: linux
OS: posix
Python: /home/lukas/anaconda3
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry --version
4Poetry version 1.1.6
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ 4
I would have expected Python to run on 3.9 or if it can’t find that version I would expect it to display an error or warning during poetry install
.
See also:
- Closed, similar issue: https://github.com/python-poetry/poetry/issues/522
- An older attempt to fix this, but not applicable if you want to develop on multiple machines: https://github.com/python-poetry/poetry/pull/731
- Another merged PR that was supposed to fix this if I understand it correctly: https://github.com/python-poetry/poetry/pull/1477
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:12 (1 by maintainers)
even though I had the variable
virtualenvs.in-project=true
, andpyenv global 3.9.0
the project root.venv
gets created with3.7.8
. When I runpoetry env info
virtualenv and python path are pointing to3.7.8
. As a work around for now I did the following:rm -rf .venv
rm poetry.lock
pyenv global 3.9.0
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
poetry env info
Now has the correct informationpoetry install
Hello everyone,
this issue seems to arise when using
pyenv
. Please note, that switching the python version used for venv creating withpyenv
only ever worked, if Poetry was installed via the (now deprecated)get-poetry.py
installation script. In any other case (install-poetry.py
,pip
,pipx
) the Python version used during installation is used and switching the Python interpreter viapyenv
has no influence.Because the
get-poetry.py
install script will not work from Poetry 1.2 on, Poetry will behave the same way here despite how it was installed and so confusions should be avoided. The “pyenv workflow” is possible by setting the experimental optionvirtualenvs.prefer-active-python
totrue
.I would asked everyone here to try out the latest preview release (1.2.0b1) to check if the problems still persist. Also please have a look at the corresponding documentation in
master
and report if there is something unclear: https://python-poetry.org/docs/master/managing-environments/Thanks for your feedback!
fin swimmer