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.

venv created with the 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).

  • OS version and name: macOS Big Sur (11.6)

  • Poetry version: 1.1.11

Issue

I have both versions 3.7.2 and 3.8.0 of python installed on my mac. My .toml states the python version should be 3.7: … [tool.poetry.dependencies] python = “~3.7” …

When i run “poetry update” (I use zsh terminal, don’t know if it matters or not) a venv is created for my project (good), its name is myproj-DbOwq67j-py3.7 (also good), but the actual files created are python 3.8 (not good!). If you navigate to that folder you can clearly see the folder name is 3.7 but the file names are 3.8. Also I had issues installing packages that can only be installed on 3.7, so no doubt this is not just a naming issue.

This is bad as it is, because that venv is forever broken unless I patch the poetry code that creates venvs, but even after patching I get another issue: Every time I close the terminal and reopen it, I run “poetry shell” to run commands for that venv, and i get this:

➜ myproj git:(master) ✗ poetry shell The currently activated Python version 3.8.0 is not supported by the project (~3.7). Trying to find and use a compatible version. Using python3 (3.7.2) The virtual environment found in /Library/Frameworks/Python.framework/Versions/3.8 seems to be broken. Recreating virtualenv myproj-DbOwq67j-py3.7 in /Users/[my user]/Library/Caches/pypoetry/virtualenvs/myproj-DbOwq67j-py3.7 Spawning shell within /Users/[my user]/Library/Caches/pypoetry/virtualenvs/myproj-DbOwq67j-py3.7 ➜ myproj git:(master) ✗ . /Users/[my user]/Library/Caches/pypoetry/virtualenvs/myproj-DbOwq67j-py3.7/bin/activate (myproj-DbOwq67j-py3.7) ➜ myproj git:(master) ✗

Which means that the venv will be recreated once more with the wrong python version and override my patching. Also I need to reinstall all packages which in this case takes like 800s. Not fun. By the way, the version in /Library/Frameworks/Python.framework/Versions/3.8 is definitely not broken, so i don’t know what that is about.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
asafalon1commented, Nov 4, 2021

From what i’m reading the other issues describe other symptoms of the same change, but the bug described here is different, so connecting is them is fine, but I dont think they are all the same issue, or should be closed as one.

The workaround is nice, by the way, but its impractical on my end, I have over 30 repos i work on, with different python versions, ranging from 3.6 to 3.10. It takes longer than doing what Im doing right now, which is create the venvs correctly once by patching the poetry code, and then disable poetry’s ability to recreate my venvs. I wouldn’t recommend this to anyone else though.

2reactions
greatvovancommented, Oct 31, 2021

I am experiencing the same issue. Also, a workaround here.

pyenv: 2.2.0 poetry: 1.1.11 MacOS 11.6

Relevant Python versions are different from @asafalon1 , but the gist is basically the same: Python binaries of the created env. are of wrong version:

% poetry shell
The currently activated Python version 3.8.6 is not supported by the project (^3.10.0).
Trying to find and use a compatible version.
Using python3 (3.10.0)
Creating virtualenv my-project-ZyKUAaQE-py3.10 in /Users/me/Library/Caches/pypoetry/virtualenvs
Spawning shell within /Users/me/Library/Caches/pypoetry/virtualenvs/my-project-ZyKUAaQE-py3.10
% . /Users/me/Library/Caches/pypoetry/virtualenvs/my-project-ZyKUAaQE-py3.10/bin/activate
(my-project-ZyKUAaQE-py3.10) % python
Python 3.8.6 (default, Dec  8 2020, 13:48:43)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
  1. The “activated” version is determined incorrectly. I tried to set both pyenv global and pyenv local to another version, but it did not change anything, and “activated” version still was 3.8.6.
  2. I made poetry env use 3.10 and it fixed the problem.

The concept of activated version is not quite clear, poetry must use the version specified in the .toml file for purposes of creating environment. What is activated version? I understand, it might make sense to select between variants of the same version (e.g. Python 3.9.7 from brew and Python 3.9.7 from pyenv), but why poetry may be using completeyl different version? Documentation was not very helpful for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Virtualenv uses wrong python, even though it is first in $PATH
My problem was that i recently moved my project with virtualenv to another location, due to this activate script had wrong VIRTUAL_ENV path....
Read more >
This virtualenv seems to have the wrong Python version (3.8 ...
Delete the virtualenv and recreate it for the version of Python that your web app is configured for and then try to make...
Read more >
Wrong python-version in virtualenv [Solved (I think) It works now]
Hello. I eariler had some problem with app.py in Ex50. This was because I did not had python version 3.6. I installed this...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
Changed in version 3.5: The use of venv is now recommended for creating virtual environments. On Windows, invoke the venv command as follows:....
Read more >
Installing and using virtualenv with Python 3
Virtualenv is only installed on DreamHost servers for Python 2. If you're working with Python 3, you must install virtualenv using pip3. pip3...
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