-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Env.run_python_script should use the executable returned by sys.executable
, avoiding "Unknown option: -I"
#8012
Comments
this doesn't look right, but per #7854 (comment) I expect this already is fixed anyway |
I'm not sure what doesn't look right about it, but it does line up with various other issues (including #7854, cited above). I'm not attached to the little POC hack as the right way to fix it, but it does seem that Poetry needs to do something to ensure that it's using the venv that it built when it was installed via curl. I'm not sure which fix you're referring to in #7977 which seems to concern in-project-venv and does not seem relevant to what I'm seeing. I'm initializing a fresh project via Also #7597, only saw the failure with v1.5.0, v1.4.2 worked for them. On the other hand, I see the failure for releases >= 1.3.0, where the Here's an example with v1.4.2$ curl -sSL https://install.python-poetry.org | python3 - --uninstall Removing Poetry (1.5.0) $ curl -sSL https://install.python-poetry.org | python3 - --version 1.4.2 Retrieving Poetry metadataWelcome to Poetry!This will download and install the latest version of Poetry, It will add the /Users/georgehartzell/.local/bin You can uninstall at any time by executing this script with the --uninstall option, Installing Poetry (1.4.2): Done Poetry (1.4.2) is installed now. Great! You can test that everything is set up by executing:
$ mkdir foo This command will guide you through creating your pyproject.toml config. Package name [foo]: Would you like to define your main dependencies interactively? (yes/no) [yes]
Package to add or search for (leave blank to skip): requests Enter package # to add, or the complete package name if it is not listed []:
Add a package (leave blank to skip): Would you like to define your development dependencies interactively? (yes/no) [yes] no [tool.poetry] [tool.poetry.dependencies] [build-system] Do you confirm generation? (yes/no) [yes] yes Command ['python', '-I', '-W', 'ignore', '-'] errored with the following return code 2 Error output: Input: if hasattr(sys, "real_prefix"): $ |
Just checked, and my version of the problem is not fixed in the master branch (just installed specifying master, should be commit f3f71ea): Example of failure using the master branch.$ curl -sSL https://install.python-poetry.org | python3 - --uninstall Welcome to Poetry!This will download and install the latest version of Poetry, It will add the /Users/georgehartzell/.local/bin You can uninstall at any time by executing this script with the --uninstall option, Installing Poetry (https://github.com/python-poetry/poetry.git@master): Done Poetry (https://github.com/python-poetry/poetry.git@master) is installed now. Great! You can test that everything is set up by executing:
$ which poetry This command will guide you through creating your pyproject.toml config. Package name [foo]: Would you like to define your main dependencies interactively? (yes/no) [yes] yes
Package to add or search for (leave blank to skip): requests Enter package # to add, or the complete package name if it is not listed []:
Add a package (leave blank to skip): Would you like to define your development dependencies interactively? (yes/no) [yes] no [tool.poetry] [tool.poetry.dependencies] [build-system] Do you confirm generation? (yes/no) [yes] yes Command ['python', '-I', '-W', 'ignore', '-'] errored with the following return code 2 Error output: Input: if hasattr(sys, "real_prefix"): $ |
the latest comment in #7854 picks out When I say "this doesn't look right" I mean that falling back to poetry's own python interpreter does not look like a desirable fix. It might or might not be safe for it would probably be better to have no fallback at all, and fail more explicitly if failing to find a good python. |
Thanks for the clarification. If I can restate your concern to see if I understand it, are you're worried that (for example) there are times when one would want to run a python script in the context of the project being worked on? Running Because python is what it is (XKCD #1987), it seems that insisting that the thing called For kicks, I changed the function to call Call python3 instead of python
|
poetry nearly always wants to run in the context of the virtual environment associated with the project being managed. virtual environments are required to have a guessing at I don't know why we're having this discussion in a new issue: if you want to submit an MR then please submit an MR, if you want to discuss #7854 then let's do it there. |
@dimbleby +1 for this comment:
|
@hartzell please close this as a duplicate |
The only problem with this is that it means that, at least on my may, poetry as installed by the recommended route doesn't work. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
/usr/bin/python
is 2.7.16curl
method.-vvv
option) and have included the output below.poetry -vvv show output
Issue
Poetry installed via curl only works if executable returned
which python
is python version 3. Otherwise it complains aboutUnknown option: -I
.A rough fix is for
Env.run_python_script
to use the same python interpreter that's runningpoetry
(e.g. as returned bysys.executable
), rather than invokingpython
(see POC change below).I'm on a mac where
/usr/bin/python
is 2.7.16 and/but I have python 3.11.3 installed via homebrew in/usr/local/bin
. The homebrew recipe does not provide an executable namedpython
that is version 3. In other words,which python
returns/usr/bin/python
and runningpython
gets v2.7.16.I've installed python using the recommended method:
This creates a virtual environment for poetry in
/Users/georgehartzell/Library/Application Support/pypoetry/venv/bin/python
and~/.local/bin/poetry
has a shebang line that ensure that the python executable used (namedpython
) is from that venv.This is enough to let simple commands run:
BUT,
Env.run_python_script
, here invokes an executable namedpython
with the-I
flag, which is new in python 3 (3.4, I think?).Because the function does not activate poetry's virtual environment, it ends up running
/usr/bin/python
, which in my case is 2.7.11 and does not support -I.This results in the error message in the "requested info" section above.
Poetry 1.5.0 works if I activate poetry's virtual environment manually first:
Things also works if I manually create a virtual environment, activate it, use
pip
to install Poetry in the venv, and work with it activated.A proof of concept fix is (apologies for just editing the installed python, but I just wanted to Prove the Concept and didn't want to figure out how to replicate the curl install for a branched fix):
The text was updated successfully, but these errors were encountered: