gpt4 book ai didi

python - 离线环境安装Python包找不到安装的依赖

转载 作者:行者123 更新时间:2023-12-04 01:02:59 26 4
gpt4 key购买 nike

我正在尝试在离线环境中从源代码安装 SQLACodegen 包及其依赖项(inflect、setuptools-scm)。具体来说,我在 Red Hat Enterprise Linux 7 系统上使用 Python 3.8 安装了 Anaconda 2020.07。

我将 Anaconda bin 目录添加到 PATH,并使用 python -m pip install whatever.tar.gz 进行安装。是的,我知道像这样使用 pip 而不是 conda 是一种罪过。碰巧这是安装上游包时更简单的方法,而且我在安装许多其他包之前从未遇到过问题。

问题是 pip 正在尝试上网下载并安装 setuptools。奇怪的是 setuptools 已经安装并且满足包的版本要求。即使我指定了诸如 --no-index -f/path/to/packages 之类的 pip 标志,它仍然无法检测到已安装的 setuptools 并尝试从某个地方拉取它。

示例输出:

[root@myserver stuff]# ls
inflect-4.1.0.tar.gz setuptools_scm-4.1.2.tar.gz sqlacodegen-2.1.0.tar.gz
[root@myserver stuff]# which python
/usr/local/anaconda-2020.07/bin/python
[root@myserver stuff]# python -V
Python 3.8.3
[root@myserver stuff]# python -m pip list | grep setuptools
setuptools 49.2.0.post20200714
[root@myserver stuff]# python -m pip install --no-index -f . sqlacodegen-2.1.0.tar.gz
Looking in links: .
Processing ./sqlacodegen-2.1.0.tar.gz
Installing build dependencies ... error
ERROR: Command errored out with exit status 1:
command: /usr/local/anaconda-2020.07/bin/python /usr/local/anaconda-2020.07/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env/r61p50oe/overlay --no-warn-script-location --no-binary :none: --only-binary :none: --no-index --find-links . -- 'setuptools >= 36.2.7' wheel 'setuptools_scm >= 1.7.0'
cwd: None
Complete output (3 lines):
Looking in links: .
ERROR: Could not find a version that satisfies the requirement setuptools>=36.2.7 (from versions: none)
ERROR: No matching distribution found for setuptools>=36.2.7

我有一种感觉 --ignore-installed 标志可能是问题的一部分,但我不知道如何覆盖它,它看起来像 pip 自己对许多选项拍打.有没有人遇到过类似的情况并解决了?

最佳答案

您需要添加 install 选项 --no-build-isolation从源代码安装时,您想告诉 Pip 使用已安装的软件包来满足构建依赖项。强调build依赖。

最常见的构建依赖关系,根据 PEP 518 , 是 setuptoolswheel。以至于,作为“构建系统执行的最低要求”,构建工具应该默认将它们添加到构建配置中。

从源代码安装新包时,Python 环境中的包在构建依赖关系方面会被忽略。作为Pip documentation explains :

When making build requirements available, pip does so in an isolated environment. That is, pip does not install those requirements into the user’s site-packages, but rather installs them in a temporary directory which it adds to the user’s sys.path for the duration of the build. This ensures that build requirements are handled independently of the user’s runtime environment. For example, a project that needs a recent version of setuptools to build can still be installed, even if the user has an older version installed (and without silently replacing that version).

(文档已经更新和改写,见 Build Process 部分,并且不再明确提到 site-packages 将被忽略,尽管这仍然是隐含的。)

在您的示例中,该临时目录似乎是 /tmp/pip-build-env/r61p50oe。除了 --no-build-isolation 选项,您还可以添加 setuptoolswheel 的源包(可能更多,具体取决于您正在安装的软件包)到通过 -f/--find-links 选项指定的本地文件夹。

关于python - 离线环境安装Python包找不到安装的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67594547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com