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

feat(pypi): fallback to virtualenv if venv fails #1682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kbenzie
Copy link

@kbenzie kbenzie commented Apr 15, 2024

On Ubuntu 22.04 when the python3-venv package is not installed:

  • Importing the venv module will succeed.
  • Running python3 -m venv --help will output help.
  • Running python3 -m venv $VENV_DIR fails with the following output:
$ python3 -m venv $VENV_DIR
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /root/venv/bin/python3

When running in a rootless environment installing the python3-venv package is not tenable. However, the virtualenv package can be installed via pip in the users home directory.

This patch checks the result of python3 -m venv $VENV_DIR, if that fails then it will fallback to calling python3 -m virtualenv $VENV_DIR instead.

@kbenzie kbenzie force-pushed the virtualenv-fallback branch 2 times, most recently from 062412e to a323b7e Compare April 15, 2024 23:04
On Ubuntu 22.04 when the `python3-venv` package is not installed:

* Importing the `venv` module will succeed.
* Running `python3 -m venv --help` will output help.
* Running `python3 -m venv $VENV_DIR` fails with the following output:

```console
$ python3 -m venv $VENV_DIR
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /root/venv/bin/python3
```

When running in a rootless environment installing the `python3-venv`
package is not tenable. However, the `virtualenv` package can be
installed via `pip` in the users home directory.

This patch checks the result of `python3 -m venv $VENV_DIR`, if that
fails then it will fallback to calling `python3 -m virtualenv $VENV_DIR`
instead.
@LarsHaalck
Copy link

I'm using the PR for multiple months now in a rootless scenario as described by kbenzie and I haven't encountered any issues. I think it would be great to get this merged. It is only a very minor change, and the user could be even warned that the fallback happens to make it more clear that this is not the default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants