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 creates virtualenv with wrong 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).
  • macOS BigSur 11.6.1 (20G224):
  • Poetry version 1.1.13:
  • Seems unrelated to pyproject.toml

Issue

I’m trying to constrain the python version within 3.9.x using:

[tool.poetry.dependencies]
python = "~3.9.0"

I have a setup of poetry + pyenv that has been working nicely so far, but poetry insists on using Python 3.10. It tells me that it’s using 3.9.9 but it runs python 3.10. Somehow it creates the virtualenv with the wrong version. image (2)

Pyenv has been set with pyenv local 3.9.9 and seems to be working correctly

image (3)

Things I’ve tried:

  • poetry env use 3.9.9
  • Delete everything (lock, venv, even cloning again) and trying again
  • tried to use another folder name (in case something was cached)
  • Ran with -vvv to check if I had more output about the venv creation

Thanks for the help!!

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
muraiicommented, Feb 13, 2022

I don’t want to create a nearly duplicate issue, but the issue I’m having is slightly different. If y’all prefer, I’ll create a new issue.

Issue:

Running curl -sSL https://install.python-poetry.org | python - installs Poetry without any errors or apparent issues. However, any attempt to use poetry new or poetry init will choose the version of Python which which Poetry was installed, independent of which version of Python has been selected as global using pyenv global <version>.

System

  • Windows 10 -> WSL2
  • Manjaro 21.2.1
  • pyenv version 2.2.3-1-g423de9ae
  • poetry version 1.1.13
  • zsh 5.8

Steps to reproduce:

$ pyenv global 3.9.9
$ python -V

Python 3.9.9

$ curl -sSL https://install.python-poetry.org | python -
$ poetry new test
$ cd test
$ poetry shell
$ python -V

Python 3.9.9

$ cd ..
$ pyenv global 3.8.5
$ python -V

Python 3.8.5

$ poetry new test2
$ cd test2
$ poetry shell
$ python -V

Python 3.9.9

Short-term Fix

If I use poetry env use 3.8.5 or whatever other version I want, and then create/activate a virtual environment with poetry shell, Poetry uses the appropriate Python version. But I think this is not expected behavior, i.e., Poetry should (and on an Ubuntu system I’ve used previously, Poetry does) choose the version of Python based on the currently activated Python version per pyenv.

1reaction
finswimmercommented, Oct 22, 2022

Hey,

this should now work correctly by setting virtualenvs.prefer-active-python to true.

fin swimmer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry doesn't use the correct version of Python - Stack Overflow
To change the specific version poetry is using you should use poetry env ... (e.g. python = ">=3.6.2 <3.7" ) after creating the...
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 >
Python Virtual Environments tutorial using Virtualenv and Poetry
A mini-guided Python tutorial showing how to use virtual environment and why it's matters on virtualenv and poetry illustrated examples.
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 >
Poetry Advance - Python Biella Group
As a result of creating a virtualenv folder within the project, vscode will recognize that this is the default virtualenv to use rather...
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