在安装gptqmodel时发现报缺少torch但明明已经安装ModuleNotFoundError: No module named ‘torch‘ [end of output]

引用:在安装mmdetection时发现报缺少torch但明明已经安装ModuleNotFoundError: No module named ‘torch‘ [end of output]_modulenotfounderror: no module named 'torch' [end -优快云博客

报错背景:
pip安装一个gptqmodel库时,明明已经安装了torch库但仍然报没有安装。

pip list
Package           Version
----------------- ----------

torch             2.6.0+cpu
torchaudio        2.6.0+cpu
torchvision       0.21.0+cpu

pip install gptqmodel
Collecting gptqmodel
  Using cached gptqmodel-2.2.0.tar.gz (284 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
  ╰─> [17 lines of output]
      Traceback (most recent call last):
        File "D:\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
          main()
        File "D:\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main
          json_out["return_val"] = hook(**hook_input["kwargs"])
        File "D:\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 143, in get_requires_for_build_wheel
          return hook(config_settings)
        File "C:\Users\30755\AppData\Local\Temp\pip-build-env-iy0284h3\overlay\Lib\site-packages\setuptools\build_meta.py", line 334, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "C:\Users\30755\AppData\Local\Temp\pip-build-env-iy0284h3\overlay\Lib\site-packages\setuptools\build_meta.py", line 304, in _get_build_requires
          self.run_setup()
        File "C:\Users\30755\AppData\Local\Temp\pip-build-env-iy0284h3\overlay\Lib\site-packages\setuptools\build_meta.py", line 522, in run_setup
          super().run_setup(setup_script=setup_script)
        File "C:\Users\30755\AppData\Local\Temp\pip-build-env-iy0284h3\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in run_setup
          exec(code, locals())
        File "<string>", line 24, in <module>
      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.


解决办法
pip cache purge 
pip install --upgrade setuptools wheel
再次安装,成功了

pip install gptqmodel
Collecting gptqmodel
  Downloading gptqmodel-2.2.0.tar.gz (284 kB)
  Preparing metadata (setup.py) ... done
Collecting accelerate>=1.3.0 (from gptqmodel)
  Downloading accelerate-1.6.0-py3-none-any.whl.metadata (19 kB)
Collecting datasets>=3.2.0 (from gptqmodel)
  Downloading datasets-3.5.0-py3-none-any.whl.metadata (19 kB)
Requirement already satisfied: numpy>=1.26.4 in d:\python\python310\lib\site-packages (from gptqmodel) (2.1.2)
Requirement already satisfied: torch>=2.2.0 in d:\python\python310\lib\site-packages (from gptqmodel) (2.6.0+cpu)
Collecting safetensors>=0.5.2 (from gptqmodel)
  Downloading safetensors-0.5.3-cp38-abi3-win_amd64.whl.metadata (3.9 kB)
Collecting transformers>=4.49.0 (from gptqmodel)
  Downloading transformers-4.51.3-py3-none-any.whl.metadata (38 kB)
Collecting threadpoolctl>=3.6.0 (from gptqmodel)
  Downloading threadpoolctl-3.6.0-py3-none-any.whl.metadata (13 kB)
Collecting packaging>=24.2 (from gptqmodel)
  Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
Collecting device-smi==0.4.1 (from gptqmodel)
  Downloading device_smi-0.4.1.tar.gz (17 kB)
  Preparing metadata (setup.py) ... done
Collecting protobuf>=5.29.3 (from gptqmodel)
  Downloading protobuf-6.30.2-cp310-abi3-win_amd64.whl.metadata (593 bytes)
Collecting pillow>=11.1.0 (from gptqmodel)
  Downloading pillow-11.2.1-cp310-cp310-win_amd64.whl.metadata (9.1 kB)
Collecting hf_transfer>=0.1.9 (from gptqmodel)
  Downloading hf_transfer-0.1.9-cp38-abi3-win_amd64.whl.metadata (1.8 kB)
Collecting huggingface_hub>=0.28.1 (from gptqmodel)
  Downloading huggingface_hub-0.30.2-py3-none-any.whl.metadata (13 kB)
Collecting random_word==1.0.13 (from gptqmodel)
  Downloading random_word-1.0.13-py3-none-any.whl.metadata (4.3 kB)
Collecting tokenicer==0.0.4 (from gptqmodel)
  Downloading tokenicer-0.0.4.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Collecting logbar==0.0.4 (from gptqmodel)
  Downloading logbar-0.0.4.tar.gz (12 kB)
  Preparing metadata (setup.py) ... done
Collecting autopep8<3.0.0,>=2.3.1 (from random_word==1.0.13->gptqmodel)

Preparing metadata (setup.py): started 939.7 Preparing metadata (setup.py): finished with status 'error' 939.8 error: subprocess-exited-with-error 939.8 939.8 × python setup.py egg_info did not run successfully. 939.8 │ exit code: 1 939.8 ╰─> [15 lines of output] 939.8 Traceback (most recent call last): 939.8 File "<string>", line 2, in <module> 939.8 exec(compile(''' 939.8 ~~~~^^^^^^^^^^^^ 939.8 # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py 939.8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 939.8 ...<31 lines>... 939.8 exec(compile(setup_py_code, filename, "exec")) 939.8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 939.8 ''' % ('/tmp/pip-install-izfd3rce/xformers_aac4a604ddb44fab834aeb08debab17f/setup.py',), "<pip-setuptools-caller>", "exec")) 939.8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 939.8 File "<pip-setuptools-caller>", line 34, in <module> 939.8 File "/tmp/pip-install-izfd3rce/xformers_aac4a604ddb44fab834aeb08debab17f/setup.py", line 24, in <module> 939.8 import torch 939.8 ModuleNotFoundError: No module named 'torch' 939.8 [end of output] 939.8 939.8 note: This error originates from a subprocess, and is likely not a problem with pip. 943.4 error: metadata-generation-failed 943.4 943.4 × Encountered error while generating package metadata. 943.4 ╰─> See above for output. 943.4 943.4 note: This is an issue with the package mentioned above, not pip. 943.4 hint: See above for details. ------ failed to solve: process "/bin/sh -c chmod +x /opt/miniconda.sh && /opt/miniconda.sh -b -p /opt/miniconda && rm -f /opt/miniconda.sh && conda create -n ultrarag python=3.10 -y && echo \"conda activate ultrarag\" >> ~/.bashrc && python -m ensurepip && p
06-10
### 解决Docker构建失败的方法 当遇到`docker build failed`错误,可能由多种原因引起。以下是几种常见的解决方案: #### 修改默认存储路径以防止内存不足 如果构建过程中遇到了类似于`failed to register layer: fatal error: runtime: out of memory`这样的错误消息,则可能是由于磁盘空间或内存资源不够造成的。通过修改Docker配置文件`daemon.json`可以调整数据根目录的位置,从而缓解这个问题。 ```json { "data-root": "/opt/apps/docker_data" } ``` 这会将Docker的数据存放在指定的新位置上,有助于释放原有分区的空间并提高性能[^3]。 #### 使用合适的镜像基础环境 确保`.gitlab-ci.yml`中的CI/CD流水线设置正确无误也很重要。对于需要运行于GitLab CI环境中带有Docker命令的任务来说,应该选用支持Docker-in-Docker(DiD)模式的基础镜像,并开启相应的服务。 ```yaml image: docker:git services: - docker:dind build: script: - docker build -t my-image . - docker push my-image ``` 上述配置指定了使用官方提供的包含Git工具链的Docker客户端作为执行上下文,并启用了守护进程形式的服务容器来提供必要的Socket接口给主流程调用[^1]。 #### 正确编写Dockerfile与关联配置文件 另外,在创建项目特定的Docker映像之前,还需要准备一份描述应用程序依赖关系及其启动方式的`Dockerfile`以及用于定义多服务应用架构布局的`docker-compose.yml`文档。这两者共同决定了最终打包成果的质量和可用性[^2]。 为了更有效地排查具体问题所在,建议查看完整的日志输出信息,定位到具体的错行数;同确认宿主机操作系统版本、内核参数设定等因素是否会对整个过程造成影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值