Skip to content
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

install-poetry fails with PIP_REQUIRE_VIRTUALENV #4089

Closed
neersighted opened this issue May 23, 2021 · 3 comments · Fixed by #4099
Closed

install-poetry fails with PIP_REQUIRE_VIRTUALENV #4089

neersighted opened this issue May 23, 2021 · 3 comments · Fixed by #4099
Labels
kind/bug Something isn't working as expected

Comments

@neersighted
Copy link
Member

neersighted commented May 23, 2021

Because install-poetry.py does not check the exit status of pip when bootstrapping the temporary virtualenv module, users are confronted with an odd error when they have $PIP_REQUIRE_VIRTUALENV set in their environment.

Output looks something like the following:

Installing Poetry...
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/home/neersighted/.local/share/pypoetry/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.1.6): Creating environment
Traceback (most recent call last):
  File "<stdin>", line 808, in <module>
  File "<stdin>", line 804, in main
  File "<stdin>", line 417, in run
  File "<stdin>", line 439, in install
  File "<stdin>", line 505, in make_env
AttributeError: module 'virtualenv' has no attribute 'cli_run'

This can easily be corrected by invoking the script again with PIP_REQUIRE_VIRTUALENV= to 'reset' the environmental variable.

For some background:
Pip provides this opt-in so that users can ensure they don't accidentally clutter or break their system installation of Python. Normally when this feature blocks execution of a command, it is called out to the user like this:

ERROR: Could not find an activated virtualenv (required).

Because pip is being invoked by install-poetry.py without checking exit status or output, this information is lost.

I would suggest explicitly resetting PIP_REQUIRE_VIRTUALENV in the installer script unconditionally to ensure that this interaction doesn't cause the failure above.

@neersighted neersighted added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 23, 2021
@abn abn added Installer and removed status/triage This issue needs to be triaged labels May 24, 2021
@neersighted
Copy link
Member Author

The installer changes proposed in #4099 greatly simplify the virtualenv-related code and solve half this issue (unexplained errors/discarded information). Now we just have to determine if the installer breaking due to this setting is a bug, or if the user is responsible for unsetting it before running the installer.

Thoughts, @sdispater?

@neersighted
Copy link
Member Author

I was wrong about this -- #4099 with actually entirely solve this issue as Poetry will no longer invoke pip outside a virtualenv! Nice!

abn added a commit to abn/poetry that referenced this issue Nov 12, 2021
This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: python-poetry#4089
Resolves: python-poetry#4093
abn added a commit to abn/poetry that referenced this issue Nov 12, 2021
This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: python-poetry#4089
Resolves: python-poetry#4093
abn added a commit to abn/poetry that referenced this issue Nov 12, 2021
This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: python-poetry#4089
Resolves: python-poetry#4093
neersighted added a commit that referenced this issue Nov 12, 2021
* installer: improve error handling and logging

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>

* installer: default to using in-built venv module

This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: #4089
Resolves: #4093

* ci/installer: upload failure logs

* installer: preserve existing environment on failure

This change ensures that if creation of a new environment fails, any
previously existing environment is restored.

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
1nF0rmed pushed a commit to 1nF0rmed/poetry that referenced this issue Nov 15, 2021
* installer: improve error handling and logging

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>

* installer: default to using in-built venv module

This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: python-poetry#4089
Resolves: python-poetry#4093

* ci/installer: upload failure logs

* installer: preserve existing environment on failure

This change ensures that if creation of a new environment fails, any
previously existing environment is restored.

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
edvardm pushed a commit to edvardm/poetry that referenced this issue Nov 24, 2021
* installer: improve error handling and logging

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>

* installer: default to using in-built venv module

This change refactors virtual environment creation and introduces a new
wrapper to handle command execution etc. If venv module is not
available, in cases like that of the ubuntu distribution where the
module is not part of the default python install, the virtualenv
package is used by fetching the appropriate zipapp for the package for
the python runtime.

Resolves: python-poetry#4089
Resolves: python-poetry#4093

* ci/installer: upload failure logs

* installer: preserve existing environment on failure

This change ensures that if creation of a new environment fails, any
previously existing environment is restored.

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants