Poetry (still) does not use active pyenv when creating virtual environment. Is it possible to write a documentation page about how to make this work?
See original GitHub issue- Poetry: Poetry (version 1.2.2)
- Python: Python: 3.10.8 (using pyenv)
- OS: MacOS 12.6.1
- pyproject.toml:
[tool.poetry]
name = "poetryproj1"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Context
Hi, I am a new users of Poetry and I am working on establishing best practices for python software packaging in our team and I thought about starting introducing Poetry in our workflow. However I may stick to pip and pyenv-virtualenv for a little bit longer as it doesnt seem that poetry is compatible with pyenv.
I think my issue is related to several issues about poetry not working as expected with pyenv such as
- https://github.com/python-poetry/poetry/issues/5252
- https://github.com/python-poetry/poetry/issues/7075
- https://github.com/python-poetry/poetry/issues/651
- https://github.com/python-poetry/poetry/issues/172
Issue
poetry doesnt use the active terminal python version defined by pyenv global 3.10.8, pyenv local 3.10.8 or pyenv shell 3.10.8, when creating a new project with the command poetry new projnew1
Reproductible example
- Install [
Poetry] with:
curl -sSL https://install.python-poetry.org | python3 -
- Add Poetry to your PATH:
echo '\n# Add Poetry to PATH\nexport PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
-
Restart the shell with
exec $SHELL -
Test the installation by running:
poetry --version
- Update Poetry:
poetry self update
- Install pyenv environment 3.10.4:
pyenv install 3.10.4
- Activate pyenv environment
pyenv global 3.10.4
- Verify active python version
pyenv which python
returns /Users/loic.houpert/.pyenv/versions/3.10.4/bin/python
- Set virtualenvs to true:
poetry config virtualenvs.prefer-active-python true
- Create a new poetry project
poetry new poetryproj1
- Read the
project.toml
ccat poetryproj1/pyproject.toml
which returns the wrong python version:
[tool.poetry]
name = "poetryproj1"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Notes
- I used the official installer,
- I also tried
poetry config virtualenvs.prefer-active-python falseorpoetry config virtualenvs.prefer-active-python truebefore creating a new project. - Does the integration
pyenv+poetryworked in the past? If yes what poetry version was it? - I happy to write some doc about pyenv+poetry integration if we manage to make this work
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
Thanks, that makes your issue more clear 👍
Respecting the current activated python version on
initandnewis already on my ToDo list as reported in #7073.Until than you have to fix the
pyproject.tomlmanually.poetry installshould than work as expected.Hello @Mahdi-Hosseinali,
this issue here is closed and solved. Please open a new one, which includes all necessary steps to reproduce your problem.
fin swimmer