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:
- Created 2 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
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.
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:
pyenv global
andpyenv local
to another version, but it did not change anything, and “activated” version still was 3.8.6.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.