question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

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

  1. Install [Poetry] with:
curl -sSL https://install.python-poetry.org | python3 -
  1. Add Poetry to your PATH:
echo '\n# Add Poetry to PATH\nexport PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
  1. Restart the shell with exec $SHELL

  2. Test the installation by running:

poetry --version
  1. Update Poetry:
poetry self update
  1. Install pyenv environment 3.10.4:
pyenv install 3.10.4
  1. Activate pyenv environment
pyenv global 3.10.4
  1. Verify active python version
pyenv which python

returns /Users/loic.houpert/.pyenv/versions/3.10.4/bin/python

  1. Set virtualenvs to true:
poetry config virtualenvs.prefer-active-python true
  1. Create a new poetry project
poetry new poetryproj1
  1. 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 false or poetry config virtualenvs.prefer-active-python true before creating a new project.
  • Does the integration pyenv+poetry worked 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:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
finswimmercommented, Nov 25, 2022

Thanks, that makes your issue more clear 👍

Respecting the current activated python version on init and new is already on my ToDo list as reported in #7073.

Until than you have to fix the pyproject.toml manually. poetry install should than work as expected.

0reactions
finswimmercommented, Dec 19, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry does not use active pyenv when creating virtual ...
I am on the latest Poetry version. I have searched the issues of this repo and believe that this is not a duplicate....
Read more >
Managing environments | Documentation - Poetry
To achieve this, it will first check if it's currently running inside a virtual environment. If it is, it will use it directly...
Read more >
Cannot switch Python with pyenv - Stack Overflow
I successfully downloaded python2 and python3 and pyenv with following codes. brew install pyenv brew install pyenv-virtualenv pyenv install 2.7.10 pyenv ...
Read more >
Configure a Pipenv environment | PyCharm Documentation
Pipenv is a tool that provides all necessary means to create a virtual environment for your Python project. It automatically manages project packages ......
Read more >
Setting up Python Projects with Pyenv & Poetry
Poetry - Manages Python virtual environments and the project dependencies within. If you're on Mac you may have a default Python 2.7 aleady ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found