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 creates virtualenv with wrong version #5190

Closed
3 tasks done
EdatWork opened this issue Feb 11, 2022 · 11 comments
Closed
3 tasks done

Poetry creates virtualenv with wrong version #5190

EdatWork opened this issue Feb 11, 2022 · 11 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@EdatWork
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • macOS BigSur 11.6.1 (20G224):
  • Poetry version 1.1.13:
  • Seems unrelated to pyproject.toml

Issue

I'm trying to constrain the python version within 3.9.x using:

[tool.poetry.dependencies]
python = "~3.9.0"

I have a setup of poetry + pyenv that has been working nicely so far, but poetry insists on using Python 3.10.
It tells me that it's using 3.9.9 but it runs python 3.10. Somehow it creates the virtualenv with the wrong version.
image (2)

Pyenv has been set with pyenv local 3.9.9 and seems to be working correctly

image (3)

Things I've tried:

  • poetry env use 3.9.9
  • Delete everything (lock, venv, even cloning again) and trying again
  • tried to use another folder name (in case something was cached)
  • Ran with -vvv to check if I had more output about the venv creation

Thanks for the help!!

@EdatWork EdatWork added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 11, 2022
@muraii
Copy link

muraii commented Feb 13, 2022

I don't want to create a nearly duplicate issue, but the issue I'm having is slightly different. If y'all prefer, I'll create a new issue.

Issue:

Running curl -sSL https://install.python-poetry.org | python - installs Poetry without any errors or apparent issues. However, any attempt to use poetry new or poetry init will choose the version of Python which which Poetry was installed, independent of which version of Python has been selected as global using pyenv global <version>.

System

  • Windows 10 -> WSL2
  • Manjaro 21.2.1
  • pyenv version 2.2.3-1-g423de9ae
  • poetry version 1.1.13
  • zsh 5.8

Steps to reproduce:

$ pyenv global 3.9.9
$ python -V

Python 3.9.9

$ curl -sSL https://install.python-poetry.org | python -
$ poetry new test
$ cd test
$ poetry shell
$ python -V

Python 3.9.9

$ cd ..
$ pyenv global 3.8.5
$ python -V

Python 3.8.5

$ poetry new test2
$ cd test2
$ poetry shell
$ python -V

Python 3.9.9

Short-term Fix

If I use poetry env use 3.8.5 or whatever other version I want, and then create/activate a virtual environment with poetry shell, Poetry uses the appropriate Python version. But I think this is not expected behavior, i.e., Poetry should (and on an Ubuntu system I've used previously, Poetry does) choose the version of Python based on the currently activated Python version per pyenv.

@mabugaj
Copy link

mabugaj commented Feb 16, 2022

For me it's the same situation. Problem in general is that poetry shows that it's installing right version but in .venv actually is being installed something else:

➜ poetry install -E redis           
The currently activated Python version 3.10.2 is not supported by the project (3.9.7).
Trying to find and use a compatible version. 
Using python3 (3.9.7)
Creating virtualenv pro-test in /home/bugaj/Documents/git/pro-test/code/.venv
Installing dependencies from lock file

After this in .venv python 3.10 is installed.

@arubin
Copy link

arubin commented Feb 16, 2022

I am getting the same inconsistent behavior - my current solution is to manually edit the virtual environment config poetry generates:

  1. Edit pyvenv.cfg in the Poetry virtual env folder
  • for my config that is located ~/Library/Caches/pypoetry/virtualenvs/
  • point all the python directories to my desired pyenv version
  1. Update the 'python' symlink in /bin
  • for my config this is located at ~/Library/Caches/pypoetry/virtualenvs//bin
  • create a new symbolic link: ln -s <pyenv executable> ./python

@finswimmer
Copy link
Member

I think this a duplicate of #5077 (comment).

@mabugaj
Copy link

mabugaj commented Feb 16, 2022

@finswimmer I think You're right (the process that You described is exactly the way I got into this situation), so the problem is with the new installation script. For the record I tried old installation script but it has other bugs on my system (latest manjaro).

One problem that I see is that I'm using 1.1.13 which should have this feature merged or am I wrong?

@muraii
Copy link

muraii commented Feb 17, 2022

I think this a duplicate of #5077 (comment).

Might be, but for my part I'd read that thread and comment and used the newer installation script after uninstalling the Poetry instance I'd installed using the older script. And this happens for whichever version of Python with which I install Poetry, so it shouldn't be a residual install issue.

@mijamo
Copy link

mijamo commented Apr 20, 2022

For me the problem seemed to be that by default 3.10 included a local folder but no bin (bin was nested into local). I created a symlink from local/bin to bin and it seemed to work after that

@qbedard
Copy link

qbedard commented Jun 1, 2022

Yeah, this happens for me even with the latest beta. 🫤

@finswimmer
Copy link
Member

Hey,

this should now work correctly by setting virtualenvs.prefer-active-python to true.

fin swimmer

@SubaruSpirit
Copy link

Hey,

this should now work correctly by setting virtualenvs.prefer-active-python to true.

fin swimmer

It didn't solve the problem though. I specified python version to be ^3.9, but it created python 3.10.4 in the virtual env

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
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

8 participants