poetry icon indicating copy to clipboard operation
poetry copied to clipboard

[Windows] poetry & poetry-win: Wrong python version

Open mfeyx opened this issue 2 years ago • 1 comments

  • [x] I am on the latest Poetry version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • Windows 10 21H2
  • 1.1.14

Issue

I use pyenv to manage my python versions on the system. For every poetry project I want to manage the version with a .python-version file. I installed poetry with the powershell command provided on the documentation page

poetry installation

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

My global python version was 3.10.5 when I installed poetry. And that is also the version I found in the pyvenv.cfg:

# C:\Users\[username]\AppData\Roaming\pypoetry\venv
home = C:\Users\[username]\.pyenv\pyenv-win\versions\3.10.5
include-system-site-packages = false
version = 3.10.5

poetry config

cache-dir = "C:\\Users\\[username]\\AppData\\Local\\pypoetry\\Cache"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\[username]\AppData\Local\pypoetry\Cache\virtualenvs

Wrong python version

The issue now is that this will always be the version, no matter what I do.

pyenv local 3.9.13
# creates .python-version with 3.9.13

python -V
# 3.9.13

poetry new myproject --src
# creates project

poetry env use python
# creates .venv folder 

.venv/pyvenv.cfg

home = C:\Users\[username]\.pyenv\pyenv-win\versions\3.10.5
implementation = CPython
version_info = 3.10.5.final.0
virtualenv = 20.16.2
include-system-site-packages = false
base-prefix = C:\Users\[username]\.pyenv\pyenv-win\versions\3.10.5
base-exec-prefix = C:\Users\[username]\.pyenv\pyenv-win\versions\3.10.5
base-executable = C:\Users\[username]\.pyenv\pyenv-win\versions\3.10.5\python.exe

Am I doing something wrong? I would expect that poetry would respect the local version. I found the poetry installation in this folder: C:\Users\[username]\AppData\Roaming\pypoetry\venv and I think this is the problem because there is only the python 3.10 installation in Scripts folder.

Thanks!

mfeyx avatar Aug 01 '22 11:08 mfeyx

I found a workaround stated in #5353:

Something I noticed if I install via the get-poetry.py installer which is not recommended anymore, the error does not occur

I just did that and used the following command:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -

It worked for me.

mfeyx avatar Aug 01 '22 11:08 mfeyx

This is solved with the experimental virtualenvs.prefer-active-python setting, and is a consequence of the new install method, which was in turn required for plugins and a variety of other improvements to Poetry.

neersighted avatar Oct 11 '22 11:10 neersighted

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[bot] avatar Mar 01 '24 05:03 github-actions[bot]