pypa / pip

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

Pip 24.2 failing to locate package already installed #12988

Closed jacobgorm closed 3 weeks ago

jacobgorm commented 3 weeks ago

Description

Trying to install a package with a setup.py that imports a package installed in the currently active venv, but not in the system python install, fails with a ModuleNotFoundError error.

Expected behavior

Expecting the depedency (torch i this case) to be found and the next package in the list (gsplat) being installed.

pip version

24.2

Python version

3.12.6

OS

Arch Linux x64

How to Reproduce


rm -rf env
python -m venv env
./env/bin/pip install torch gsplat

gsplat's setup.py imports torch, but fails with a ModuleNotFoundError, even though torch is clearly installed in the venv: Se below for the output.

Output

Collecting torch
  Using cached torch-2.4.1-cp312-cp312-manylinux1_x86_64.whl.metadata (26 kB)
Collecting gsplat
  Using cached gsplat-1.4.0.tar.gz (105 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      Setting MAX_JOBS to 10
      Traceback (most recent call last):
        File "/home/jacob/dev/vertigo-ai/train/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/jacob/dev/vertigo-ai/train/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/jacob/dev/vertigo-ai/train/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ejwj6rhk/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ejwj6rhk/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-ejwj6rhk/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 503, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-ejwj6rhk/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 318, in run_setup
          exec(code, locals())
        File "<string>", line 137, in <module>
        File "<string>", line 33, in get_extensions
      ModuleNotFoundError: No module named 'torch'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Code of Conduct

notatallshaw commented 3 weeks ago

When a package is being built, it is by default built in an isolated build environment, it is up to the package (in this case gsplat) to correctly define build requirements: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#declaring-the-build-backend

If the package doesn't provide any build requirements you must install the requirements yourself first, and then install the package with --no-build-isolation.

This isn't a pip issue, you should reach out to the package for support for how to install it.