pip: Assertion Error: assert not (home and prefix)

Environment

  • pip version: 20.1.1
  • Python version: 3.8.3
  • OS: Windows 10

PIP_CACHE_DIR = D:\Environments\Python\pip cache dir PIP_TARGET = D:\Environments\Python\Lib\site-packages

Description

A weird error when I tried to install pyinstaller

Expected behavior install normally

How to Reproduce

pip install pyinstaller

Output

Collecting pyinstaller
  Using cached PyInstaller-3.6.tar.gz (3.5 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 2:
   command: 'd:\environments\python\python.exe' 'd:\environments\python\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'D:\Environments\TEMP\pip-build-env-siqaoa6a\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel
       cwd: None
  Complete output (22 lines):
  Collecting setuptools>=40.8.0
    Using cached setuptools-47.1.1-py3-none-any.whl (583 kB)
  Collecting wheel
    Using cached wheel-0.34.2-py2.py3-none-any.whl (26 kB)
  Installing collected packages: setuptools, wheel
  ERROR: Exception:
  Traceback (most recent call last):
    File "d:\environments\python\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
      status = self.run(options, args)
    File "d:\environments\python\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
      return func(self, options, args)
    File "d:\environments\python\lib\site-packages\pip\_internal\commands\install.py", line 398, in run
      installed = install_given_reqs(
    File "d:\environments\python\lib\site-packages\pip\_internal\req\__init__.py", line 67, in install_given_reqs
      requirement.install(
    File "d:\environments\python\lib\site-packages\pip\_internal\req\req_install.py", line 769, in install
      scheme = get_scheme(
    File "d:\environments\python\lib\site-packages\pip\_internal\locations.py", line 185, in get_scheme
      scheme = distutils_scheme(
    File "d:\environments\python\lib\site-packages\pip\_internal\locations.py", line 118, in distutils_scheme
      assert not (home and prefix), "home={} prefix={}".format(home, prefix)
  AssertionError: home=D:\Environments\TEMP\pip-target-wydanjze prefix=D:\Environments\TEMP\pip-build-env-siqaoa6a\overlay
  ----------------------------------------
ERROR: Command errored out with exit status 2: 'd:\environments\python\python.exe' 'd:\environments\python\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'D:\Environments\TEMP\pip-build-env-siqaoa6a\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel Check the logs for full command output.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I was getting a similar error with pip 22.3 & Python 3.7.3 on Windows 10: ERROR: Cannot set --home and --prefix together.

The work around was to remove target from the global field in file C:\Users\<USER>\AppData\Roaming\pip\pip.ini and provide the target as a CLI argument to pip install: --target path\to\site-packages.

This was fixed by #12744, so closing.

I had this problem now too while installing a local package like this: python3 -m pip install -U . I have the PIP_TARGET variable set, which seems to be the culprit. However, I was able to workaround this, by building a wheel first and then installing the wheel:

python3 setup.py bdist_wheel
python3 -m pip install -U dist/mypackage*.whl

pip 21.2.4 / python 3.9.7 I also tested with 22.0.4 but the only difference is the new shiny error message (they look really good! But do not solve the issue 😅)

I had a similar issue and solved it with the sudo’s -H flag: sudo -H pip install pyinstaller

But it works if --target is specified via command line (since this way PIP_TARGET doesn’t get propagated to the subprocess):

$ pip install --target site-packages cryptography==3.0

The closest alternatives are --prefix (PIP_PREFIX), and --root (doesn’t work with an environment variable either).

P.S. Make sure to set PYTHONPATH=site-packages or something to be able to import the packages.

Hi @McSinyx, I did not use --prefix. I do not understand why this error happens as well. It installs successfully if I remove the PIP_TARGET environment variables. I also have other environment variables set, not sure if they are related:

TEMP=D:\Environments\TEMP
TMP=D:\Environments\TEMP
TMPDIR=D:\Environments\TEMP