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

Pip install doesn't recognize torch #1814

Open
gboeer opened this issue Dec 10, 2024 · 1 comment
Open

Pip install doesn't recognize torch #1814

gboeer opened this issue Dec 10, 2024 · 1 comment

Comments

@gboeer
Copy link

gboeer commented Dec 10, 2024

In my current setup, when installing yolox, the installation process exits with an error:

pip install -v -e .
AssertionError: torch is required for pre-compiling ops, please install it first.

However, torch is installed in my environment, as returned by pip list:

torch 2.0.1+cu117
torchvision 0.15.2+cu117

I am working with the most recent version:
d872c71

My python version is:

python --version
Python 3.10.15

The full error message is:

Using pip 24.2 from /home/appuser/.local/venv/lib/python3.10/site-packages/pip (python 3.10)
Obtaining file:///develop/YOLOX
  Running command pip subprocess to install build dependencies
  Using pip 24.2 from /home/appuser/.local/venv/lib/python3.10/site-packages/pip (python 3.10)
  Collecting setuptools>=40.8.0
    Obtaining dependency information for setuptools>=40.8.0 from https://files.pythonhosted.org/packages/55/21/47d163f615df1d30c094f6c8bbb353619274edccf0327b185cc2493c2c33/setuptools-75.6.0-py3-none-any.whl.metadata
    Using cached setuptools-75.6.0-py3-none-any.whl.metadata (6.7 kB)
  Using cached setuptools-75.6.0-py3-none-any.whl (1.2 MB)
  Installing collected packages: setuptools
  Successfully installed setuptools-75.6.0
  Installing build dependencies ... done
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Getting requirements to build editable
  [WARNING] Unable to import torch, pre-compiling ops will be disabled.
  Traceback (most recent call last):
    File "/home/appuser/.local/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/home/appuser/.local/venv/lib/python3.10/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/appuser/.local/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
      return hook(config_settings)
    File "/tmp/pip-build-env-_ks8t9e7/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 483, in get_requires_for_build_editable
      return self.get_requires_for_build_wheel(config_settings)
    File "/tmp/pip-build-env-_ks8t9e7/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=[])
    File "/tmp/pip-build-env-_ks8t9e7/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-_ks8t9e7/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 522, in run_setup
      super().run_setup(setup_script=setup_script)
    File "/tmp/pip-build-env-_ks8t9e7/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in run_setup
      exec(code, locals())
    File "<string>", line 77, in <module>
    File "<string>", line 50, in get_ext_modules
  AssertionError: torch is required for pre-compiling ops, please install it first.
  error: subprocess-exited-with-error
  
  × Getting requirements to build editable 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.
  full command: /home/appuser/.local/venv/bin/python3 /home/appuser/.local/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py get_requires_for_build_editable /tmp/tmpn2i8m2cc
  cwd: /develop/YOLOX
  Getting requirements to build editable ... error

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
error: subprocess-exited-with-error

× Getting requirements to build editable 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.
@gboeer
Copy link
Author

gboeer commented Dec 10, 2024

I managed to isolate the issue and find a workaround, which I’ll leave here for anyone facing similar challenges.

The main issue with this version of Yolo is that it seems to not be well-tested for newer Python versions, as well as for newer versions of pip and other dependencies.

I was trying to install Yolo on a headless Ubuntu 20.04.6 LTS (Focal Fossa) Docker image with Python 3.10.15, and encountered multiple issues.

Problem 1: torch Not Found During pip install -e .

The initial issue was that the torch package wasn’t found when running pip install -e .. After some investigation, I discovered that this is related to the changes in pip starting from version 10, where it began using isolated build environments during package installation. In these environments, torch wasn’t being installed, which caused the import error.

Solution for Problem 1:
The simple solution was to bypass the isolated build environment by running the installation with the --no-build-isolation flag:

pip install -v -e . --no-build-isolation

While this should ideally work with the correct setup.py, I tried adding torch to setup_requires in the setup.py file, but that didn’t resolve the issue. The isolation was still causing the problem.

Problem 2: invalid command 'bdist_wheel' Error

After solving the torch issue, I encountered another error:

error: invalid command 'bdist_wheel'

This error occurred because the wheel package, which is required to build .whl (wheel) distributions, wasn’t installed.

Solution for Problem 2:
The solution was to install or upgrade the setuptools and wheel packages:

pip install --upgrade setuptools wheel

Once setuptools and wheel were updated, the installation process completed successfully.

Conclusion:
After these steps, I was able to install Yolo on Python 3.10.15 without further issues. Now, I’m going to test if the model actually runs, but at least the installation is complete. Hopefully, this workaround helps anyone encountering similar issues when using newer Python and pip versions!

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

No branches or pull requests

1 participant