Tagged with #poetry

Workaround for when poetry cannot find pyenv managed python

I use pyenv to manage python versions for my projects, and use poetry to manage project dependencies. Poetry was unable to find the latest python version, and insisted on creating virtual envs with system python.

Setting poetry config virtualenvs.prefer-active-python true did not work for me, and neither did poetry env use whatever-version:

$ poetry env use 3.11
Could not find the python executable python3.11

However pyenv can list the the full path to the currently active python, which can be used as a parameter to poetry, so the following worked:

$ poetry env use $(pyenv which python)
$ poetry install; poetry run python --version

Update: double check that pyenv is configuring the shell correctly -- $HOME/.pyenv/shims should be in your PATH variable, and your shell runtime configuration file (such as .bashrc / .zshrc) should contain eval "$(pyenv init -)"

Hope this helps!

#poetry #python #pyenv #ubuntu #elementaryos

June 16, 2023 at 11:23 am