python系列&deep_study系列:【已解决】 error: subprocess-exited-with-error × python setup.py egg_info did not r




【已解决】 error: subprocess-exited-with-error × python setup.py egg_info did not run successfully.

问题描述

今天遇到这个问题:ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/pkg_resources/__init__.py),其实这种问题很常见,希望给大家统一讲一下如何处理的,我们从头开始!

具体描述为:

Collecting torch_sparse
  Using cached torch_sparse-0.6.18.tar.gz (209 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-mu4fnmkw/torch-sparse_7b1f67db8d584e36bedf832159648d4b/setup.py", line 11, in <module>
          from torch.utils.cpp_extension import (
        File "/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
          from pkg_resources import packaging  # type: ignore[attr-defined]
      ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/pkg_resources/__init__.py)
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
 
× Encountered error while generating package metadata.
╰─> See above for output.
 
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
(gdem) visionx@visionx:/media/visionx/monica/project24/GDEM$ pip install torch_sparse
Collecting torch_sparse
  Using cached torch_sparse-0.6.18.tar.gz (209 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-11nj3e0o/torch-sparse_e89b9d926f354738a403de89b0c3a695/setup.py", line 11, in <module>
          from torch.utils.cpp_extension import (
        File "/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
          from pkg_resources import packaging  # type: ignore[attr-defined]
      ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/pkg_resources/__init__.py)
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
 
× Encountered error while generating package metadata.
╰─> See above for output.
 
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

看图:

在这里插入图片描述

原因分析和解决

1、在我的主页搜索torch

在这里插入图片描述

2、结果如下,点击113这个

在这里插入图片描述

3、选择这个网址https://pytorch-geometric.com/whl/

在这里插入图片描述

4、选择对应版本安装,命令为:

pip install torch_sparse-0.6.18+pt21cu118-cp38-cp38-linux_x86_64.whl

在这里插入图片描述

5、解决

相关链接

Python Setup.py Egg_info Error Code (Solution) | Master Data Skills + AI
While working with Python packages, programmers may encounter a specific error — ‘python setup.py egg_info’ failed with error code 1. This error is related to the package installation process and can arise due to several reasons, such as outdated or improperly installed pip or other package installation tools. You can fix the ‘python setup.py egg_info’
https://blog.enterprisedna.co/python-setup-py-egg_info-error-code/


https://pytorch-geometric.com/whl/torch-2.1.2%2Bcu118.html
https://pytorch-geometric.com/whl/torch-2.1.2%2Bcu118.html

完结撒花

结束了,都结束了。







鳗小鱼

【已解决】 error: subprocess-exited-with-error × python setup.py egg_info did not run successfully.

<think>好的,我现在需要帮助用户解决在运行`python setup.py egg_info`时出现的`subprocess-exited-with-error`的问题。首先,我应该回想一下这个错误通常是什么原因引起的。通常来说,这类错误可能和Python环境、依赖项的版本或者`setup.py`本身的配置有关。 用户提到了引用[1]中的内容,虽然具体的引用内容不是很明确,但可能涉及错误输出的日志。所以,我需要指导用户如何根据错误日志来诊断问题。首先,用户需要检查完整的错误输出,因为里面可能有具体的错误信息,比如缺少某个模块、版本不兼容,或者语法错误等。 接下来,常见的解决步骤可能包括升级setuptools和pip,因为过时的工具可能会导致兼容性问题。例如,用户可以使用`pip install --upgrade setuptools pip`来升级。此外,确保虚拟环境正确配置也是一个关键点,尤其是在使用venv或conda的情况下。用户可能需要创建新的虚拟环境,并重新安装依赖。 另外,依赖项的版本冲突也是一个常见问题。用户可能需要检查项目中的requirements.txt或者setup.py中的依赖版本,尝试安装指定版本的包。有时候,手动安装缺失的依赖项可以解决问题,比如错误提示中提到的某个包无法找到,用户可以直接用pip安装它。 如果问题仍然存在,检查setup.py文件的语法是否正确也很重要。是否有拼写错误,或者使用了过时的配置方式?有时候,项目可能需要使用更现代的构建工具,比如poetry或flit,而不是传统的setup.py。 还有一个可能性是Python版本不兼容。用户需要确认他们使用的Python版本是否与项目要求的版本匹配。如果项目需要Python 3.7,而用户使用的是3.10,可能会有兼容性问题,这时候可以尝试降低Python版本或者寻找项目的更新版本。 最后,如果所有方法都无效,用户可能需要寻求更具体的帮助,比如在GitHub的问题区提问,或者查看是否有其他人遇到相同的问题。提供完整的错误日志对于进一步诊断问题至关重要。 总结一下,解决步骤可能包括: 1. 检查错误日志中的具体信息。 2. 升级setuptools和pip。 3. 使用虚拟环境并重新安装依赖。 4. 确保依赖项版本正确。 5. 检查setup.py的语法和配置。 6. 确认Python版本兼容性。 7. 寻求社区帮助,提供详细错误信息。 在这个过程中,需要逐步排除可能的原因,并验证每一步是否有效。同时,提醒用户在操作前备份项目,避免意外情况。</think>### 解决 `python setup.py egg_info` 的 `subprocess-exited-with-error` 问题 #### 1. 检查完整错误日志 首先需查看完整的报错信息,通常包含缺失依赖、版本冲突或语法错误。例如: ```bash Complete output from command python setup.py egg_info: ERROR: Could not find a version that satisfies the requirement some-package>=1.0.0 ``` 此类信息会直接指向问题根源[^1]。 #### 2. 升级工具链 过时的 `setuptools` 或 `pip` 可能导致兼容性问题: ```bash pip install --upgrade setuptools pip ``` #### 3. 使用虚拟环境 隔离环境可避免系统级依赖冲突: ```bash python -m venv myenv source myenv/bin/activate # Linux/macOS # 或 myenv\Scripts\activate.bat (Windows) pip install -r requirements.txt ``` #### 4. 安装缺失依赖 若错误提示缺少特定包,手动安装: ```bash pip install missing-package==x.x.x # 替换为实际包名和版本 ``` #### 5. 检查 `setup.py` 语法 确保文件中无语法错误或过时配置。例如: ```python # 正确声明依赖的方式 install_requires=[ 'numpy>=1.18.0', 'requests>=2.25.1' ] ``` #### 6. 尝试替代安装方式 使用 `pip` 直接安装项目可能绕过 `setup.py` 问题: ```bash pip install . # 在当前目录安装 ``` #### 7. 验证Python版本 确认项目支持的Python版本: ```bash python --version # 若不匹配,使用pyenv或conda切换版本 ``` #### 8. 清理重建 删除旧编译文件避免残留影响: ```bash rm -rf build/ dist/ *.egg-info/ # Linux/macOS pip install --force-reinstall . ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坦笑&&life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值