python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.06k stars 2.25k forks source link

poetry install didn't find the correct python version set by pyenv #9619

Open doyaklee opened 1 month ago

doyaklee commented 1 month ago

Description

Hello. I'd like to use poetry to manage python packages for global python environment set by pyenv in Windows. So, I first install and set python 3.12.5 using pyenv

> pyenv install 3.12.5
> pyenv global 3.12.5

Then, in the arbitrary folder containing pyproject.toml file with python = 3.12.5 in it, I install python packages with following commands

> poetry config virtualenvs.create false
> poetry lock
> poetry install

So far, it worked fine globally.
Problems happened when I tried to switch my global environment to 3.13.0rc1. I try to do the same thing, but it seems that poetry install stuck to previous 3.12.5 version even though python points to 3.13.0rc1

> pyenv install 3.13.0rc1
> pyenv global 3.13.0rc1
> poetry install
## Skipping virtualenv creation, as specified in config file.
## Installing dependencies from lock file
##
## No dependencies to install or update
> python  # leads to python3.13.0rc1

How could I utilize poetry to manage global python package management with pyenv? Please give me some hints. Thanks!

Workarounds

  1. delete the previous pyenv version using pyenv uninstall 3.12.5
  2. uninstall and reinstall poetry
  3. reinstall packages using poetry : poetry install

Poetry Installation Method

install.python-poetry.org

Operating System

Windows 10

Poetry Version

1.8.3

Poetry Configuration

cache-dir = "C:\\Users\\doyaklee\\AppData\\Local\\pypoetry\\Cache"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
solver.lazy-wheel = true
virtualenvs.create = false
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\doyaklee\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

Python Sysconfig

cache-dir = "C:\\Users\\doyaklee\\AppData\\Local\\pypoetry\\Cache"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
solver.lazy-wheel = true
virtualenvs.create = false
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
Platform: "win-amd64"
Python version: "3.13"
Current installation scheme: "nt"

Paths:
        data = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        include = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Include"
        platinclude = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Include"
        platlib = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib\site-packages"
        platstdlib = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib"
        purelib = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib\site-packages"
        scripts = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Scripts"
        stdlib = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib"

Variables:
        BINDIR = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        BINLIBDEST = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib"
        EXE = ".exe"
        EXT_SUFFIX = ".cp313-win_amd64.pyd"
        INCLUDEPY = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Include"
        LDLIBRARY = "python313.dll"
        LIBDEST = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\Lib"
        LIBDIR = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1\libs"
        LIBRARY = "python313.dll"
        Py_GIL_DISABLED = "0"
        SOABI = "cp313-win_amd64"
        TZPATH = ""
        VERSION = "313"
        VPATH = "..\.."
        abi_thread = ""
        abiflags = ""
        base = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        exec_prefix = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        implementation = "Python"
        implementation_lower = "python"
        installed_base = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        installed_platbase = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        platbase = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        platlibdir = "DLLs"
        prefix = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        projectbase = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        py_version = "3.13.0rc1"
        py_version_nodot = "313"
        py_version_nodot_plat = "313"
        py_version_short = "3.13"
        srcdir = "C:\Users\doyaklee\.pyenv\pyenv-win\versions\3.13.0rc1"
        userbase = "C:\Users\doyaklee\AppData\Roaming\Python"

Example pyproject.toml

[tool.poetry]
package-mode = false 

[tool.poetry.dependencies]
python = "3.12.5"    
pip = "^24.0.0"
pipdeptree = "*"
graphviz ="*"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

It's not failed.
dimbleby commented 1 month ago

poetry config virtualenvs.create false

Don't do that

doyaklee commented 1 month ago

poetry config virtualenvs.create false

Don't do that

What I want to do is to install dependencies into the system environment, and as I understand, this is what exactly virtualenvs.create false intended as written in the documentation. So, I can't understand why I shouldn't do that

If set to false, Poetry will not create a new virtual environment. If it detects an already enabled virtual environment or an existing one in {cache-dir}/virtualenvs or {project-dir}/.venv it will install dependencies into them, otherwise it will install dependencies into the systems python environment.

dimbleby commented 1 month ago

What I want to do is to install dependencies into the system environment

No, you don't want to do that.

If you insist on pursuing this, you can check how poetry determines the "system" environment here, and figure out what it is doing. I guess it is using the-python-that-poetry-itself-was-installed-with.

But I highly recommend just not doing what you are doing.