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 uses wrong Python version

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).

Issue

We’re developing a project on a few machines with several different Python versions installed. We’re using Poetry to make sure we have the same development environment. But unfortunately Poetry doesn’t check if the right Python version is installed. I expect to get an error or a warning if Poetry isn’t running on the Python version specified in the pyproject.toml file (Python 3.9). But Poetry lets this slip, so when working on my laptop the other day I only got a failure at runtime when suddenly tons of errors with type annotation popped up. It took me a while to figure out this was because I was using an old Python version (3.8).

To reproduce, copy the pyproject.toml linked above and run the following commands:

(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry install
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry run python
Python 3.8.5 (default, Sep  4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry env info
Virtualenv
Python:         3.8.5
Implementation: CPython
Path:           /home/lukas/.cache/pypoetry/virtualenvs/edeo-sensing-iAOxxtc0-py3.8
Valid:          True
System
Platform: linux
OS:       posix
Python:   /home/lukas/anaconda3
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ poetry --version
4Poetry version 1.1.6
(base) lukas@ThinkPad-T560:~/Desktop/poetry_test$ 4

I would have expected Python to run on 3.9 or if it can’t find that version I would expect it to display an error or warning during poetry install.

See also:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
redeemefycommented, Nov 17, 2021

even though I had the variable virtualenvs.in-project=true, and pyenv global 3.9.0 the project root .venv gets created with 3.7.8. When I run poetry env info virtualenv and python path are pointing to 3.7.8. As a work around for now I did the following:

  • rm -rf .venv
  • rm poetry.lock
  • pyenv global 3.9.0
  • python -m venv .venv
  • source .venv/bin/activate
  • python -m pip install --upgrade pip
  • poetry env info Now has the correct information
  • poetry install
7reactions
finswimmercommented, Apr 29, 2022

Hello everyone,

this issue seems to arise when using pyenv. Please note, that switching the python version used for venv creating with pyenv only ever worked, if Poetry was installed via the (now deprecated) get-poetry.py installation script. In any other case (install-poetry.py, pip, pipx) the Python version used during installation is used and switching the Python interpreter via pyenv has no influence.

Because the get-poetry.py install script will not work from Poetry 1.2 on, Poetry will behave the same way here despite how it was installed and so confusions should be avoided. The “pyenv workflow” is possible by setting the experimental option virtualenvs.prefer-active-python to true.

I would asked everyone here to try out the latest preview release (1.2.0b1) to check if the problems still persist. Also please have a look at the corresponding documentation in master and report if there is something unclear: https://python-poetry.org/docs/master/managing-environments/

Thanks for your feedback!

fin swimmer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry using the wrong Python version (not related to pyenv)
Poetry should implicitly create a built-in virtual environment with the Python version specified by the tool.poetry.dependencies.python property ...
Read more >
Poetry doesn't use the correct version of Python - Stack Overflow
It seems that Poetry defaults back to the system version of Python. How do I change this so that it uses the version...
Read more >
Managing environments | Documentation - Poetry
By default, Poetry will try to use the Python version used during Poetry's installation to create the virtual environment for the current project....
Read more >
Configure a Poetry environment | PyCharm Documentation
Poetry is a tool that facilitates creating a Python virtual environment based on the project dependencies. You can declare the libraries your project ......
Read more >
Select python interpreter in poetry | by Jamie Thomson - Medium
I used poetry to discover the version of python currently being used in the project: As you can see it is using python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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