-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
- Poetry version: 1.2.2
- Python version: CPython 3.9.12
- OS version and name: MacOS (darwin) 12.6.1 Monterey (ARM architecture)
- pyproject.toml: See below
- I am on the latest stable Poetry version, installed using a recommended method.
- I have searched the issues of this repo and believe that this is not a duplicate. Related but not the same as far as I can tell:
Poetry not using the correct python version #7075
Poetry does not set the path for or activate the virtual environment if the active python version differs from that used to install poetry #6978
poetry env info has wrong virtualenv info #6893 - I have consulted the FAQ and blog for any relevant entries or release notes.
- (N/A) If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
If Poetry's internal virtual environment (used to execute Poetry) doesn't match the version resolved by the python3 command, then Poetry doesn't select the correct Python version (defined in pyproject.toml) for installation when creating a new virtual environment for a project.
There are two different ways that I've found to achieve this scenario.
Scenario 1:
- Install Python 3.10 (or 3.9 or 3.8, just referring to 3.10 from now on) from https://python.org (using standard installer)
- (Now
$PATHresolvespython3to3.10) - Run
curl -sSL https://install.python-poetry.org | python3 -as officially supported installation mechanism - Install Python 3.11 from https://python.org
- (Now
$PATHresolvespython3to3.11)
Scenario 2:
- Install Python 3.9 (or any version other than 3.11) from https://python.org (using standard installer)
- Install Python 3.11 from https://python.org
- (Now
$PATHresolvespython3to3.11) - Run
curl -sSL https://install.python-poetry.org | python3.9 -
Outcome
Relaunch the terminal to ensure $PATH changes take effect.
$ poetry install --no-root
The currently activated Python version 3.9.12 is not supported by the project (~3.11).
Trying to find and use a compatible version.
Using python3 (3.11.0)
Creating virtualenv poetrytest in /Users/scott/Documents/automation/poetrytest/.venv
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing attrs (22.1.0)This all looks correct, but then I activate the virtual environment with source .venv/bin/activate.
Expected
The shell prompt shows (poetrytest-py3.11) and python --version shows 3.11.0. I would also expect poetry shell to work in place of source .venv/bin/activate.
Actual
The shell prompt shows (poetrytest-py3.11) and python --version shows 3.9.12 (or whatever older version I used).
$ poetry shell
Current Python version (3.9.12) is not allowed by the project (~3.11).
Please change python executable via the "env use" command.I've had a colleague verify this behaviour on their MacOS machine as well, and another colleague indicated that it may work properly on Ubuntu (but I have not verified that first hand).
Files
poetry.toml
[virtualenvs]
in-project = truepyproject.toml (minimal packages just to show installation)
[tool.poetry]
name = "poetrytest"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "~3.11"
attrs = "^22.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"poetry.lock
[[package]]
name = "attrs"
version = "22.1.0"
description = "Classes Without Boilerplate"
category = "main"
optional = false
python-versions = ">=3.5"
[package.extras]
dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy (>=0.900,!=0.940)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "sphinx", "sphinx-notfound-page", "zope.interface"]
docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"]
tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "zope.interface"]
tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"]
[metadata]
lock-version = "1.1"
python-versions = "~3.11"
content-hash = "088f78f8dc08e7c9c2577c94e3669da3a7f2e3a6a2c4caa83caa754e5c626bef"
[metadata.files]
attrs = [
{file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"},
{file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"},
]