将 python 项目构建为包,无需访问互联网

ste*_*ano 5 python pip build package

我有一个python项目想要打包。python -m build当连接到互联网时,我可以很好地打包该项目。

pip当我断开连接并尝试相同的命令时,出现无法找到该包的错误wheel

(my-venv) [me@my-host my-project]$ python -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools>=42, wheel)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f5935bb4f10>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/wheel/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f5935b5a160>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/wheel/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f5935b5a310>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/wheel/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f5935b5a4c0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/wheel/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f5935b5a670>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/wheel/
ERROR: Could not find a version that satisfies the requirement wheel
ERROR: No matching distribution found for wheel
Run Code Online (Sandbox Code Playgroud)

即使我先安装,也会发生这种setuptools情况wheel

如何在构建时不需要互联网访问的情况下构建我的项目?我可以以某种方式让隔离环境使用我的 python 缓存吗?

jkl*_*mnn 1

我最近也遇到了同样的问题。不幸的是,您似乎无法修改中所示的build调用方式。pipsrc/build/env.py:113

但是您可以pip通过环境变量进行配置。我所做的是设置PIP_CONFIG_FILE.

在我的特定情况下,我只设置配置文件以避免pip使用索引:

[global]
no-index = true
Run Code Online (Sandbox Code Playgroud)

然后,您可以提供一个包含所有必需依赖项的目录作为轮子,并通过环境变量进行设置PIP_FIND_LINKS。或者,您可以在配置文件中设置链接(可以指向 URL 或本地目录)或索引。