-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry uses wrong Python version #4101
Comments
I'm having this issue too, it looks like when poetry looks for a compatible python version, it calls whichever Minimal example with pyenv: $ pyenv install 3.9.5
$ pyenv install 3.8.10
$
$ # force poetry to be called with python 3.8 (also assuming pyproject.toml requried python ^3.9)
$ ~/.pyenv/versions/3.8.10/bin/python3.8 ~/.poetry/bin/poetry run python --version
The currently activated Python version 3.8.10 is not supported by the project (^3.9).
Trying to find and use a compatible version.
Using python3 (3.9.2)
Creating virtualenv ttst in /tmp/test/.venv
Python 3.8.10 I'm only seeing this problem on FreeBSD 13, and not on Linux, probably because I'm using pyenv, so when I call poetry in my project (which has a compatible |
Well, I can reproduce this issue like so (see below). I seems that poetry does not pick up the right python version when pyenv is used.
|
@sdispater Update: The root cause is mixing the interpreter discovery logic between |
It looks like you could use virtualenvs --try-first-wtith option to fix this, if this is an appropriate solution let me know, I'd be happy to submit a PR for it |
I reproduced this and give the explanation as follows:
Poetry tries the "currently activated Python executable" first to see if the version is compatible. See Then poetry will try "system Python executables" to see if there's a compatible executable. The version info is gathered from running a shell call to the "executables". Here's the trying commands: python3 -V
python3.9 -V
python3.8 -V
...
python2 -V
python2.7 -V
... See In
So, we can solve this problem by passing the path of the Python executable to |
As @NickBeeuwsaert mentioned above, another option from |
even though I had the variable
|
I think I have this same issue, and would like to point out that it causes the example given in the documentation of how to use (If my issue is different than this issue, let me know, and I will create a separate issue). Despite installing and specifying pyenv which python
/Users/igor/.pyenv/versions/miniconda3-latest/bin/python
pyenv versions
system
3.10.0
3.8.6
* miniconda3-latest (set by /Users/igor/.pyenv/version)
miniconda3-latest/envs/house_offer_analyzer
poetry init
This command will guide you through creating your pyproject.toml config.
Package name [poetry-env-test]:
Version [0.1.0]:
Description []:
Author [Igor ***, n to skip]:
License []:
Compatible Python versions [^3.8]:
Would you like to define your main dependencies interactively? (yes/no) [yes] n
Would you like to define your development dependencies interactively? (yes/no) [yes] n
Generated file
[tool.poetry]
name = "poetry-env-test"
version = "0.1.0"
description = ""
authors = ["Igor ***"]
[tool.poetry.dependencies]
python = "^3.8"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Do you confirm generation? (yes/no) [yes] y
pyenv install 3.9.8
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.8.tar.xz...
-> https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tar.xz
Installing Python-3.9.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.8 to /Users/igor/.pyenv/versions/3.9.8
pyenv local 3.9.8
poetry add click
Creating virtualenv poetry-env-test-uX9f7DhA-py3.8 in /Users/igor/Library/Caches/pypoetry/virtualenvs
Using version ^8.0.3 for click
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing click (8.0.3)
poetry env info
Virtualenv
Python: 3.8.11
Implementation: CPython
Path: /Users/igor/Library/Caches/pypoetry/virtualenvs/poetry-env-test-uX9f7DhA-py3.8
Valid: True
System
Platform: darwin
OS: posix
Python: /Users/igor/.pyenv/versions/miniconda3-latest
pyenv versions
system
3.10.0
3.8.6
* 3.9.8 (set by /Users/igor/Documents/dev/poetry-env-test/.python-version)
miniconda3-latest
miniconda3-latest/envs/house_offer_analyzer
echo $PATH
/Users/igor/.pyenv/shims /Users/igor/.pyenv/versions/miniconda3-latest/bin /Users/igor/.pyenv/versions/miniconda3-latest/condabin /opt/homebrew/bin /opt/homebrew/sbin /Users/igor/.platformio/penv/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin /usr/local/MacGPG2/bin /Users/igor/.local/bin |
Ubuntu 20.04 on WSL, Poetry version 1.1.13 Just bumping to say this one stung me too (3.9.5 used globally by pyenv and specified in To reproduce, did a The workaround by @redeemefy above has fixed for now. |
I have a similar problem on OSX, if I use the system version in poetry install
Creating virtualenv myproject-Sco6aV2r-py3.10...
...
poetry shell
(myproject-Sco6aV2r-py3.10) ➜ myproject python3 --version
Python 3.10.2 Workaround: ➜ myproject poetry env use /usr/local/opt/[email protected]/bin/python3
Creating virtualenv myproject-Sco6aV2r-py3.9 ...
(myproject-Sco6aV2r-py3.9) ➜ myproject python3 --version
Python 3.9.12 NOTE: If I try a version other than system, poetry install will fail with an appropriate message, which it what led me to the workaround. |
Hello everyone, this issue seems to arise when using Because the 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 Thanks for your feedback! fin swimmer |
@finswimmer Thanks to you I was able to fix this problem. $ poetry -V
Poetry version 1.1.14
# Install preview release
$ poetry self update --preview
$ poetry -V
Poetry (version 1.2.0b3)
# virtualenvs.prefer-active-python = true
$ poetry config virtualenvs.prefer-active-python true |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
-vvv
option).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: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:
The text was updated successfully, but these errors were encountered: