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

No module named 'torch' - Only when upgrade pip is run? [Python 3.10, Torch 1.13.1] #4921

Closed
porpoisestudios opened this issue Apr 19, 2023 · 4 comments

Comments

@porpoisestudios
Copy link

Instructions To Reproduce the 🐛 Bug:

  1. Full runnable code or full changes you made:
I'm attempting to build an environment in Docker.  I've read through all the threads and tried all the suggestions, but running into this weird issue.  I can get the detectron install to work if I don't run `RUN pip3 install --upgrade pip`, but of course I want the pip manager upgraded...

Here's the Dockerfile for repro:

FROM python:3.10-slim-bullseye

WORKDIR /app
SHELL ["/bin/bash", "-c"]

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apt-get -y update && \
    apt-get install -y --no-install-recommends build-essential && \
    apt-get install -y cmake && \
    apt install -y git

ENV VIRTUAL_ENV=/venv
RUN python3 -m venv ${VIRTUAL_ENV}
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# if this is not done, detectron2 will succeed
# if this is done, detectron2 will fail with no module named 'torch'
# RUN pip3 install --upgrade pip

RUN pip3 install --no-cache-dir torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1
RUN pip3 install 'git+https://github.com/facebookresearch/detectron2.git'

CMD [ "python3" ]

  1. What exact command you run: docker build -t test .
  2. Full logs or other relevant observations:
 > [7/7] RUN pip3 install 'git+https://github.com/facebookresearch/detectron2.git':                                                                                                   
#10 0.787 Collecting git+https://github.com/facebookresearch/detectron2.git                                                                                                           
#10 0.788   Cloning https://github.com/facebookresearch/detectron2.git to /tmp/pip-req-build-tmknku78                                                                                 
#10 0.791   Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/detectron2.git /tmp/pip-req-build-tmknku78                                       
#10 3.836   Resolved https://github.com/facebookresearch/detectron2.git to commit ebb26b5b0d914a9fc196da303e536892165a7113                                                            
#10 3.839   Installing build dependencies: started
#10 7.350   Installing build dependencies: finished with status 'done'
#10 7.351   Getting requirements to build wheel: started
#10 7.589   Getting requirements to build wheel: finished with status 'error'
#10 7.592   error: subprocess-exited-with-error
#10 7.592   
#10 7.592   × Getting requirements to build wheel did not run successfully.
#10 7.592   │ exit code: 1
#10 7.592   ╰─> [17 lines of output]
#10 7.592       Traceback (most recent call last):
#10 7.592         File "/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
#10 7.592           main()
#10 7.592         File "/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
#10 7.592           json_out['return_val'] = hook(**hook_input['kwargs'])
#10 7.592         File "/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
#10 7.592           return hook(config_settings)
#10 7.592         File "/tmp/pip-build-env-x4t67g1o/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
#10 7.592           return self._get_build_requires(config_settings, requirements=['wheel'])
#10 7.592         File "/tmp/pip-build-env-x4t67g1o/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
#10 7.592           self.run_setup()
#10 7.592         File "/tmp/pip-build-env-x4t67g1o/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 484, in run_setup
#10 7.592           super(_BuildMetaLegacyBackend,
#10 7.592         File "/tmp/pip-build-env-x4t67g1o/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
#10 7.592           exec(code, locals())
#10 7.592         File "<string>", line 10, in <module>
#10 7.592       ModuleNotFoundError: No module named 'torch'
#10 7.592       [end of output]
#10 7.592   
#10 7.592   note: This error originates from a subprocess, and is likely not a problem with pip.
#10 7.593 error: subprocess-exited-with-error
#10 7.593 
#10 7.593 × Getting requirements to build wheel did not run successfully.
#10 7.593 │ exit code: 1
#10 7.593 ╰─> See above for output.
#10 7.593 
#10 7.593 note: This error originates from a subprocess, and is likely not a problem with pip.
------
executor failed running [/bin/bash -c pip3 install 'git+https://github.com/facebookresearch/detectron2.git']: exit code: 1
  1. please simplify the steps as much as possible so they do not require additional resources to
    run, such as a private dataset.

Expected behavior:

Should find torch. But if I comment out the line to update pip, it works.

Environment:

Provide your environment information using the following command:

(Can't run below since image is not built successfully, but my dev machine is Macosx Ventura 13.2 on an M1 chipset)
wget -nc -q https://github.com/facebookresearch/detectron2/raw/main/detectron2/utils/collect_env.py && python collect_env.py

If your issue looks like an installation issue / environment issue,
please first try to solve it yourself with the instructions in
https://detectron2.readthedocs.io/tutorials/install.html#common-installation-issues

@jabbershort
Copy link

I am having the same issue, seems to affect pip version 23. I downgraded to pip 22.* and it worked fine. Specifically, I went form 23.1.1 down to 22.3.1.

@ppwwyyxx
Copy link
Contributor

The latest pip should be used with --no-build-isolation flag

@porpoisestudios
Copy link
Author

This worked, thank you so much!

FYI: Had to install a few more dependencies prior:

RUN pip3 install wheel numpy cython

@JohnYangSam
Copy link

This was incredibly helpful! Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants