首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当试图在python中安装库时,如何修复构建环境中不可用的setuptools?

当试图在python中安装库时,如何修复构建环境中不可用的setuptools?
EN

Stack Overflow用户
提问于 2022-06-10 08:00:00
回答 1查看 4.6K关注 0票数 3

我试图在Docker中安装一个requirements.txt文件,当我在试图安装importlib时得到这个错误时,我会将它设置为大约30个包:

无法执行setup.py,因为setuptools在构建环境中不可用。

以下是完整的错误消息:

代码语言:javascript
运行
复制
Collecting importlib==1.0.4
#9 14.42   Downloading importlib-1.0.4.zip (7.1 kB)
#9 14.43   Preparing metadata (setup.py): started
#9 14.45   Preparing metadata (setup.py): finished with status 'error'
#9 14.45   error: subprocess-exited-with-error
#9 14.45   
#9 14.45   × python setup.py egg_info did not run successfully.
#9 14.45   │ exit code: 1
#9 14.45   ╰─> [1 lines of output]
#9 14.45       ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
#9 14.45       [end of output]
#9 14.45   
#9 14.45   note: This error originates from a subprocess, and is likely not a problem with pip.
#9 14.45 error: metadata-generation-failed
#9 14.45 
#9 14.45 × Encountered error while generating package metadata.
#9 14.45 ╰─> See above for output.
#9 14.45 
#9 14.45 note: This is an issue with the package mentioned above, not pip.
#9 14.45 hint: See above for details.

在Dockerfile中,我尝试过在安装包之前安装setuptools:

代码语言:javascript
运行
复制
RUN python3 -m pip install setuptools
RUN python3 -m pip install -r requirements.txt

进一步的细节:我的python版本是3.9,pip版本是22.1.2

当我这么做

代码语言:javascript
运行
复制
easy_install --version

,我得到

代码语言:javascript
运行
复制
setuptools 41.0.1 from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (Python 2.7)

然而,当我尝试用pip安装setuptools时,它说我有62.3.3版本的python3.9

代码语言:javascript
运行
复制
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (62.3.3)

任何帮助都是非常感谢的,如果我需要提供更多的细节,请告诉我。

EN

回答 1

Stack Overflow用户

发布于 2022-07-06 13:36:58

正如注释中提到的,出现此错误是因为您试图在Python3.9上安装importlib,而它只适用于更老的Python版本。

只需从您的importlib文件中删除requirements.txt

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72570910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档