Skip to content
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 (still) does not use active pyenv when creating virtual environment. Is it possible to write a documentation page about how to make this work? #7095

Closed
lhoupert opened this issue Nov 25, 2022 · 9 comments
Labels
status/duplicate Duplicate issues

Comments

@lhoupert
Copy link

lhoupert commented Nov 25, 2022

  • 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
@lhoupert lhoupert added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 25, 2022
@finswimmer
Copy link
Member

Hello @lhoupert,

because using pyenv together with Poetry works well for me and a lot of other users when setting virtualenvs.prefer-active-python to true, there must be a problem with your setup or there is an edge case we are not aware yet.

To debug this, we need a reproducible example. At best with docker container.

fin swimmer

@lhoupert
Copy link
Author

Thanks @finswimmer for the quick reply. I edited my issue with a reproducible example. I am using MacOS, can you built a docker container based on a macosx image?

@finswimmer
Copy link
Member

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.

@lhoupert
Copy link
Author

Sorry I missed #7073 , I will watched this issue. Thank you for your work!

@finswimmer finswimmer closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2022
@neersighted neersighted added status/duplicate Duplicate issues and removed kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 25, 2022
@Mahdi-Hosseinali
Copy link

I should add that if virtualenvs.create is set to false, poetry won't respect virtualenvs.prefer-active-python setting. Also, the virtualenv plugin of pyenv does create virtual environments but poetry still creates its own virtual environment when both of these settings are the default value. This is inconsistent with the documentation of virtualenvs.create.

@finswimmer
Copy link
Member

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

@garrettargenna
Copy link

I don't think this issue should actually be closed. I understand there is a separate issue for getting poetry init and poetry new working with virtualenvs.prefer-active-python but if you simply take the reproducible example above and changing step 11 to poetry install or poetry update, we still get an error like:
"The currently activated Python version 3.10.10 is not supported by the project (3.10.8).
Trying to find and use a compatible version."
If for example poetry was installed on 3.10.10 and the pyenv global version is 3.10.8
Given the title of this issue it's probably the closest to what is needed to call out the issue.

@dimbleby
Copy link
Contributor

if you simply take the reproducible example above and changing step 11 to poetry install or poetry update

nonsense, if you take that example and change step 11 as you suggest then you don't even have a poetry project and so poetry will tell you that it can't find a pyproject.toml.

whatever you are trying to report is not the same as what this issue reports.

Anyway this issue is closed. If you think you have a new problem then raise a new issue - but please first search for actual duplicates eg #7075 sounds closer.

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/duplicate Duplicate issues
Projects
None yet
Development

No branches or pull requests

6 participants