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

Unset PIP_REQUIRE_VIRTUALENV when running 'pip' #90

Closed
adamchainz opened this issue Sep 9, 2020 · 0 comments · Fixed by #91
Closed

Unset PIP_REQUIRE_VIRTUALENV when running 'pip' #90

adamchainz opened this issue Sep 9, 2020 · 0 comments · Fixed by #91

Comments

@adamchainz
Copy link
Contributor

This is the same issue as in pep517: pypa/pyproject-hooks#84

If PIP_REQUIRE_VIRTUALENV is set (to a non-empty value) when running python -m build , pip errors with its "ERROR: Could not find an activated virtualenv (required)." message:

$ python -m build
Looking in links: /var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/tmpo1xlgb08
Processing /private/var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/tmpo1xlgb08/setuptools-47.1.0-py3-none-any.whl
Processing /private/var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/tmpo1xlgb08/pip-20.1.1-py2.py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip setuptools
ERROR: Could not find an activated virtualenv (required).
Traceback (most recent call last):
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/site-packages/build/__main__.py", line 176, in <module>
    main(sys.argv[1:], 'python -m build')
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/site-packages/build/__main__.py", line 168, in main
    build(args.srcdir, args.outdir, distributions, config_settings, not args.no_isolation, args.skip_dependencies)
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/site-packages/build/__main__.py", line 80, in build
    _build_in_isolated_env(builder, outdir, distributions)
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/site-packages/build/__main__.py", line 45, in _build_in_isolated_env
    env.install(builder.build_dependencies)
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/site-packages/build/env.py", line 176, in install
    subprocess.check_call(cmd)
  File "/Users/chainz/.pyenv/versions/3.8.5/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Users/chainz/.pyenv/versions/3.8.5/bin/python', '-m', 'pip', 'install', '--prefix', '/var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/build-env-9j1lejv3', '-r', '/var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/build-reqs-cc8vednw.txt']' returned non-zero exit status 3.

The solution is to unset the environment variable for the subprocess.

adamchainz added a commit to adamchainz/python-build that referenced this issue Sep 9, 2020
Fixes pypa#90.

[The `--isolated` option](https://github.com/pypa/pip/blob/89a51a6fefec826256fb334ea6244dfb0b3455a0/src/pip/_internal/cli/cmdoptions.py#L153) ignores environment variables and user configuration, so only the passed command will be run. This fixes `python -m build` for users with `PIP_REQUIRE_VIRTUALENV`, and maybe some other cases.

I'm not sure if it will break other flows though, such as if a proxy is configured.
adamchainz added a commit to adamchainz/python-build that referenced this issue Sep 10, 2020
adamchainz added a commit to adamchainz/python-build that referenced this issue Sep 10, 2020
adamchainz added a commit to adamchainz/python-build that referenced this issue Sep 10, 2020
@FFY00 FFY00 closed this as completed in #91 Sep 11, 2020
@pypa pypa locked and limited conversation to collaborators Jan 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant