question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poetry stuck at `pyenv` Python version active during `install-poetry`, broken after version uninstall

See original GitHub issue
  • 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).
    • no exception occurs, only Shell error
  • OS version and name:
    • macOS Big Sur 11.2.3
  • Poetry version:
    • 1.1.7 via install-poetry.py
  • Link of a Gist with the contents of your pyproject.toml file:
    • provided inside [Issue] section

Issue

Below scenarios demonstrate that:

  1. Poetry 1.1.7 which was installed via install-poetry.py, does not recognize the changes in Python version made via pyenv local <version>. The expected behavior is to recognize Python version activated via pyenv. Similar issue: Poetry does not use active pyenv when creating virtual environment #651
  2. Poetry becomes broken after pyenv Python version, which have been active at a time of Poetry installation via install-poetry.py, was uninstalled via pyenv.

Out-of-the-head suggestion is that/Users/username/Library/Application Support/pypoetry/venv/bin/python should link to pyenv Python shims, not to a specific pyenv Python version, as it happens currently.

The environment:

  • pyenv 2.0.3 via Homebrew
  • Python 3.8.8 installed via pyenv, activated in a Poetry project dir via .python-version file. No other versions of Python installed via pyenv
  • Poetry 1.1.7 installed via curl + install-poetry.py from the Poetry project dir, i.e. an active version of Python at a time of installation was 3.8.8
  • Poetry appended to PATH via .zshrc: export PATH="$PATH:$HOME/.local/bin", echo $PATH output: /Users/username/.pyenv/shims:/usr/local/bin:<skipped>:/Users/username/.local/bin
  • pyproject.toml specifies Python version requirement via [tool.poetry.dependencies]: python = "^3.8.8"
  • poetry.lock specifies Python version requirement: python-versions = "^3.8.8"
  • poetry.toml: in-project = true
  • at the beginning, no .venv present in a Poetry project dir

Commands in below scenarios executed from Poetry project dir /Users/username/workspace/project/.

Scenario 1 (positive). Poetry Python version is the same as pyenv Python version:

  • pyenv versions. The result (w and p are softlinks to workspace and project dirs):
  system
  3.8.8 (set by /Users/username/w/p/.python-version)
  • python --version. The result: Python 3.8.8
  • poetry run python --version. The result:
Creating virtualenv project in /Users/username/workspace/project/.venv
Python 3.8.8

Scenario 2 (negative). Switchinig Python version via pyenv:

  • follow [Scenario 1]
  • delete .venv from Poetry project dir
  • install Python 3.7.11 via pyenv, activate it: pyenv install 3.7.11, pyenv local 3.7.11
  • pyenv versions. The result:
  system
* 3.7.11 (set by /Users/username/w/p/.python-version)
  3.8.8
  • python --version. The result: Python 3.7.11
  • poetry run python --version. The result:
Creating virtualenv project in /Users/username/workspace/project/.venv
Python 3.8.8

Expected result: poetry prints Python version Python 3.7.11, or maybe a Python version compatibility error (because the Poetry project requires a version 3.8.8 or later).

Scenario 3 (negative). Uninstalling of non-active pyenv Python version, .venv is still present:

  • follow [Scenario 2]
  • pyenv uninstall 3.8.8, after that: poetry run python --version. The result:
/Users/username/.local/bin/poetry: line 2: /Users/username/Library/Application Support/pypoetry/venv/bin/python: No such file or directory
/Users/username/.local/bin/poetry: line 2: exec: /Users/username/Library/Application Support/pypoetry/venv/bin/python: cannot execute: No such file or directory

Expected result: Poetry is not broken, and either prints the actual Python version, or a reasonable and meaningful error.

Scenario 4 (negative). Uninstalling of non-active pyenv Python version, .venv is absent:

  • follow [Scenario 3]
  • delete .venv from Poetry project dir
  • poetry run python --version. The result: the same result as for [Scenario 3].

Expected result: The same expected result as for [Scenario 3].

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
mbahricommented, Sep 15, 2021

I think this change although understandable is a bit unfortunate, as the pyenv + poetry workflow is quite popular and powerful.

It would be good to at least explain this limitation in the documentation, though. I spent hours today trying to figure out why the workflow was broken, before I noticed it was working fine with the old get-poetry.py

2reactions
princelySidcommented, Mar 10, 2022

Just in case someone end up here after hours debugging do the usual flow then poetry env use <python version>. Should work after that. Would be nice if the documentation changed to reflect this though

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry stuck at `pyenv` Python version active during `install-poetry ...
Poetry stuck at `pyenv` Python version active during `install-poetry`, broken after version uninstall.
Read more >
pyenv: poetry itself, running on older python version, what to do?
The decision is to use Pyenv to install Poetry. If the older python version should be deleted: Uninstall Poetry. Delete old Python version....
Read more >
Announcing Poetry 1.2.0 | Blog
Poetry 1.2 drops runtime support for Python 2.7, 3.5 and 3.6. Running Poetry on these versions is now untested and unsupported.
Read more >
Django setup in 2022 with pyenv + Poetry on macOS - Medium
In this article, we'll get our local mac set up using pyenv and Poetry to install specific older versions of Python and Django...
Read more >
A Poetic Apology. Or Why Should You Use Poetry to Manage…
and run your code in post mortem debugging mode with python -m pdb -cc data.py ... Now since you've locked Pandas to an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found