pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.53k stars 3.03k forks source link

Wrong install directory on pip install editable #10802

Closed jacktraror closed 6 months ago

jacktraror commented 2 years ago

Description

Problem

When installing a local package as in editable mode to venv, during the installation process, the installation directory is changed:

Expected: D:\project-name\.venv\Lib\site-packages\ Found: C:\Program Files\project-name\.venv\Lib\site-packages\ - (non existant)

and the following error thrown:

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [WinError 5] Access is denied: 'c:\\program files\\project-name'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    C:\Program Files\project-name\Lib\site-packages\

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).

Environment

Attempted steps

  1. using a clean virtual environment
  2. no configurations for pip installation directory found
  3. workaround of issue #7953

Workaround

It is possible to work around this issue by adding the following argument:

pip install --install-option="--install-dir=.\\.venv\\Lib\\site-packages" -e .

In this case, the installation process ends sucessfully and all dependencies are correctly installed.

Files

requirements.txt

pytest
cx_Freeze

Setup.py

from setuptools import find_packages
from cx_Freeze import setup, Executable

setup(
    name="project_name",
    version="0.0.1",
    packages=find_packages(),
    entry_points={"console_scripts": ["entry=project-src.cli:cli"]},
    executables=[Executable("custom-executable.py")],
    install_requires=[
        "numpy",
        "pandas",
        "matplotlib",
        "toml",
        "tqdm",
    ],
)

Expected behavior

No error and the local project is installed to the virtual environnment as editable dependency.

pip version

21.3.1

Python version

3.9.9

OS

Windows 10

How to Reproduce

  1. python -m venv .venv
  2. .\.venv\Scripts\Activate.ps1
  3. python -m pip install --upgrade pip
  4. pip install -r requirements.txt
  5. pip install -e .

Output

PS D:\project-name> python -m venv .venv
PS D:\project-name> .\.venv\Scripts\Activate.ps1
(.venv) PS D:\project-name> python -m pip install --upgrade pip
Requirement already satisfied: pip in d:\project-name\.venv\lib\site-packages (21.2.4)
Collecting pip
  Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-21.3.1
(.venv) PS D:\project-name> pip install -r requirements.txt    
Collecting pytest
  Using cached pytest-6.2.5-py3-none-any.whl (280 kB)
Collecting cx_Freeze
  Using cached cx_Freeze-6.9-cp39-cp39-win_amd64.whl (207 kB)
Collecting iniconfig
  Using cached iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting py>=1.8.2
  Using cached py-1.11.0-py2.py3-none-any.whl (98 kB)
Collecting pluggy<2.0,>=0.12
  Using cached pluggy-1.0.0-py2.py3-none-any.whl (13 kB)
Collecting atomicwrites>=1.0
  Using cached atomicwrites-1.4.0-py2.py3-none-any.whl (6.8 kB)
Collecting attrs>=19.2.0
  Using cached attrs-21.4.0-py2.py3-none-any.whl (60 kB)
Collecting colorama
  Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting packaging
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting importlib-metadata>=4.3.1
  Using cached importlib_metadata-4.10.1-py3-none-any.whl (17 kB)
Collecting cx-logging>=3.0
  Using cached cx_Logging-3.0-cp39-cp39-win_amd64.whl (26 kB)
Collecting zipp>=0.5
  Using cached zipp-3.7.0-py3-none-any.whl (5.3 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
  Using cached pyparsing-3.0.6-py3-none-any.whl (97 kB)
Installing collected packages: zipp, pyparsing, toml, py, pluggy, packaging, iniconfig, importlib-metadata, cx-logging, colorama, attrs, atomicwrites, pytest, cx-Freeze
Successfully installed atomicwrites-1.4.0 attrs-21.4.0 colorama-0.4.4 cx-Freeze-6.9 cx-logging-3.0 importlib-metadata-4.10.1 iniconfig-1.1.1 packaging-21.3 pluggy-1.0.0 py-1.11.0 pyparsing-3.0.6 pytest-6.2.5 toml-0.10.2 zipp-3.7.0
(.venv) PS D:\project-name> pip install -e .
Obtaining file:///D:/project-name
  Preparing metadata (setup.py) ... done
Collecting numpy
  Using cached numpy-1.22.1-cp39-cp39-win_amd64.whl (14.7 MB)
Collecting pandas
  Using cached pandas-1.3.5-cp39-cp39-win_amd64.whl (10.2 MB)
Collecting matplotlib
  Using cached matplotlib-3.5.1-cp39-cp39-win_amd64.whl (7.2 MB)
Requirement already satisfied: toml in d:\project-name\.venv\lib\site-packages (from project-name==0.0.1) (0.10.2)
Collecting tqdm
  Using cached tqdm-4.62.3-py2.py3-none-any.whl (76 kB)
Requirement already satisfied: pyparsing>=2.2.1 in d:\project-name\.venv\lib\site-packages (from matplotlib->project-name==0.0.1) (3.0.6)
Collecting python-dateutil>=2.7
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting fonttools>=4.22.0
  Using cached fonttools-4.28.5-py3-none-any.whl (890 kB)
Requirement already satisfied: packaging>=20.0 in d:\project-name\.venv\lib\site-packages (from matplotlib->project-name==0.0.1) (21.3)
Collecting cycler>=0.10
  Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting kiwisolver>=1.0.1
  Using cached kiwisolver-1.3.2-cp39-cp39-win_amd64.whl (52 kB)
Collecting pillow>=6.2.0
  Using cached Pillow-9.0.0-cp39-cp39-win_amd64.whl (3.2 MB)
Collecting pytz>=2017.3
  Using cached pytz-2021.3-py2.py3-none-any.whl (503 kB)
Requirement already satisfied: colorama in d:\project-name\.venv\lib\site-packages (from tqdm->project-name==0.0.1) (0.4.4)
Collecting six>=1.5
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pytz, python-dateutil, pillow, numpy, kiwisolver, fonttools, cycler, tqdm, pandas, matplotlib, project-name
  Running setup.py develop for project-name
    ERROR: Command errored out with exit status 1:
     command: 'D:\project-name\.venv\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'D:\\project-name\\setup.py'"'"'; __file__='"'"'D:\\woreplace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
    Complete output (17 lines):
    running develop
    error: can't create or remove files in install directory

    The following error occurred while trying to add or remove files in the
    installation directory:

        [WinError 5] Access is denied: 'c:\\program files\\project-name'

    The installation directory you specified (via --install-dir, --prefix, or
    the distutils default setting) was:

        C:\Program Files\project-name\Lib\site-packages\

    This directory does not currently exist.  Please create it and try again, or
    choose a different installation directory (using the -d or --install-dir
    option).

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\project-name\.venv\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'D:\\project-name\\setup.py'"'"'; __file__='"'"'D:\\project-name\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

Code of Conduct

uranusjr commented 2 years ago

I cannot reproduce, everything works right for me.

Since pip seemed to invoke setuptools with the correct parameters, this may be a setuptools issue and not pip.

ichard26 commented 6 months ago

Closing due to lack of a reproducer and follow-up. We can always revisit this later.