-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry uses the wrong version of Python #62910
Comments
It is probably a path and environment issue rather than the Homebrew package itself. You also probably have both macOS versions 2 and 3 and a homebrew version of python3 as a homebrew dependency. default - macOS system version for python
using pyenv - previously installed python 3.7.4 via pyenv
with pyenv you can set and manage versions for system/global, shell and local virtual environments You can also extend this with virtualenv using pyenv-virtualenv and have environments for each Python verson and an environment for each project and there specific dependence's. e.g environments could be 3.8.5, project1, 3.8.5/envs/project1 but that’s of scope for this ticket. |
Might also be related to issue #62911 regarding version 3.8 and 3.9 from homebrew causing issues. |
I don't want to use a second python environment manager to manage my python environment manager ;-). Poetry can handle this workaround itself by typing Poetry's own installer doesn't have this problem, so it would be nice if we could figure out a way to make Homebrew's work just as well. I really appreciate having all my installed software managed by Homebrew. |
I belive that should be
|
Either one works. |
Just use pyenv without pyenv-virtualenv for the different versions of Python then and use the virtual environments with poetry with its virtualenv support. Poetry actually recommends using pyenv to manage multiple Python versions on the page you referenced. I use pyenv-virtualenv because I haven't always been using poetry.
Ah okay |
Interesting, they do recommend pyenv. What a wild ride. If I install pyenv, then pyenv will install its own versions of Python completely independently from Homebrew python. That has some advantages. It's pretty heavyweight, though. The Poetry managing environments page also says:
So at the very least, it's clear that Homebrew Poetry is misbehaving. |
I think you’re right, I am wondering if its todo with the fact that the formula has Python 3.9 as a dependency and that the installer generates a poetry launcher file where the hash-bang is hardcoded to the absolute path of the Python 3.9 dependency it also sets up some other paths. (bin/"poetry").write <<~PYTHON
#!#{Formula["[email protected]"].opt_bin/"python3"}
import sys
sys.path.insert(0, "#{site_packages}")
sys.path.insert(0, "#{vendor_site_packages}")
if __name__ == "__main__":
from poetry.console import main
main()
PYTHON homebrew-core/Formula/poetry.rb Line 195 in d1b6def
So poetry basically always runs under Python 3.9. However, the launcher file generated by the get-poetry.py script uses f.write(u("#!/usr/bin/env {}\n".format(python_executable)))
so poetry runs under the Python set in the environment which it changes where as the homebrew formula version ignores this and runs poetry under python 3.9 always. I wonder if you run the following if it proves this?
|
Inside my
prints
I changed the shebang of |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I have the same or similar problem. I want to use python 3.6 for my project, yet somehow poetry's env is "locked" to my system's Homebrew 3.9.0 python version. Even if I try forcing the environment in poetry (with a pyenv version), the behavior is the same. 11:15:40|new$ pyenv local 3.6.12
(new-lHUWv3XF-py3.6)
11:24:13|new$ poetry env use $(pyenv which python)
Using virtualenv: /Users/juanmirocks/Library/Caches/pypoetry/virtualenvs/new-lHUWv3XF-py3.6
(new-lHUWv3XF-py3.6)
11:24:18|new$ poetry env info
Virtualenv
Python: 3.9.0
Implementation: CPython
Path: /Users/juanmirocks/Library/Caches/pypoetry/virtualenvs/new-lHUWv3XF-py3.6
Valid: True
System
Platform: darwin
OS: posix
Python: /usr/local/Cellar/[email protected]/3.9.0_2/Frameworks/Python.framework/Versions/3.9
(new-lHUWv3XF-py3.6)
11:24:23|new$ poetry run env python --version
Python 3.9.0
(new-lHUWv3XF-py3.6) |
Read above it is hardcoded to use the current python version from HomeBrew which is a dependency. tbh I don't use HomeBrew for I think I can fix it but it might go against the Homebrew guidelines by taking out this dependency. |
I understand. Thank you for your clarification. I cannot tell here with any expertise. I kinda see that Homebrew / pyenv / poetry clash somehow with each other in their assumptions. I only know that from a user perspective... I would expect to install poetry with Homebrew... and then things "just work". On top of that, if we keep the recipe as it is, AFAIHK poetry is unusable & broken under Homebrew (unless one always uses the latest Python version). That is, I see 2 solutions:
|
The best test for that is a PR. I'd appreciate it if you can propose a fix. I don't know if it'll be accepted, but it could be worth a shot. Now that I've re-read the thread properly, is the fix you had in mind the change suggested here, @andrewcrook? #62910 (comment) If so, then I would be surprised if it weren't accepted. Do you want to open a PR? I'll do it if you'd rather not. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Poetry users may wish to use it with a different version of Python, but that doesn't work if the path to Homebrew Python is hardcoded in the shebang. Fixes Homebrew#62910.
Poetry users may wish to use it with a different version of Python, but that doesn't work if the path to Homebrew Python is hardcoded in the shebang. Fixes #62910. Closes #70422. Signed-off-by: Sean Molenaar <[email protected]> Signed-off-by: BrewTestBot <[email protected]>
Bug report
Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.
brew update
and can still reproduce the problem?brew doctor
, fixed all issues and can still reproduce the problem?brew gist-logs <formula>
(where<formula>
is the name of the formula that failed) and included the output link?brew gist-logs
didn't work: ranbrew config
andbrew doctor
and included their output with your issue?What you were trying to do (and why)
I am trying to use
poetry
to manage a Python environment. My environment depends on a 3.8.x version of Python (because some packages I depend on don't yet install correctly with 3.9).What happened (include command output)
Poetry erroneously uses Python 3.9, the version it depends on, instead of 3.8.x, the version I requested.
Command output
What you expected to happen
I expected Poetry to set up a Python 3.8.x environment like my
pyproject.toml
specifies. Installing poetry in the recommended manner outside of Homebrew (via theirget-poetry.py
script) or using the default Homebrew Pythonpip install poetry
works correctly.The recommended installation page includes a warning about the issue I encountered: "Using alternative installation methods will make Poetry always use the Python version for which it has been installed to create virtualenvs."
So either I expect Homebrew's poetry to solve this problem or else print a caveat when installing poetry that it won't correctly select the Python interpreter.
Step-by-step reproduction instructions (by running
brew install
commands)brew install poetry mkdir poetry-python-version cd poetry-python-version
Place the following into a file named
pyproject.toml
in the current directory:Create the environment and check the Python version:
The output of these commands is as follows:
The interpreter really is the unwanted 3.9. It can run new Python 3.9 syntax:
When I install
poetry
using their recommendedget-poetry.py
script outside of Homebrew, or I install using Homebrew Python'spip install poetry
, the above works correctly.The text was updated successfully, but these errors were encountered: