在一个隔离环境中的 pyproject.toml

huangapple go评论76阅读模式
英文:

pyproject.toml in an isolated environment

问题

我尝试在隔离的环境中使用 pyproject.toml(特别是 setuptools_scm)。我的最小 pyproject.toml 如下:

[build-system]
requires = ["setuptools-scm"]

[tool.setuptools_scm]
write_to = "mypackage/version.py"

然而,在尝试在隔离的环境中安装我的包时,我遇到了以下问题:

$ pip3 install --no-index  -e .
获取文件:///home/…/myproject
  安装构建依赖项... 错误
  错误:子进程退出并出现错误
  
  × 运行 pip 子进程以安装构建依赖项时未成功运行。
  │ 退出码:1
  ╰─> [2 行输出]
      错误:找不到满足要求 setuptools>=40.8.0 的版本(来自版本:none)
      错误:未找到与 setuptools>=40.8.0 匹配的分发版
      [输出结束]
  
  注意:此错误源自子进程,可能与 pip 无关。
错误:子进程退出并出现错误

× 运行 pip 子进程以安装构建依赖项时未成功运行。
│ 退出码:1
╰─> 请参见上面的输出。

注意:此错误源自子进程,可能与 pip 无关。

然而,setuptools 和 setuptools_scm 已经安装(setuptools 版本为 66.1.1,setuptools_scm 版本为 7.1.0)。没有旧的 setup.py

如何确保我的包可以在没有网络访问的情况下安装(假设所有依赖项已经解决)?

英文:

I am trying to use pyproject.toml (and specifically setuptools_scm) in an isolated environment. My minimal pyproject.toml is:

[build-system]
requires = ["setuptools-scm"]

[tool.setuptools_scm]
write_to = "mypackage/version.py"

However, when trying to install my package in an isolated environment, I get:

$ pip3 install --no-index  -e .
Obtaining file:///home/…/myproject
  Installing build dependencies ... error
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [2 lines of output]
      ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
      ERROR: No matching distribution found for setuptools>=40.8.0
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies 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.

However, setuptools and setuptools_scm are already installed (setuptools 66.1.1, setuptools_scm 7.1.0). There is no legacy setup.py.

How can I ensure my package can be installed without network access (supposing that all dependencies are already resolved)?

答案1

得分: 1

以下是您要翻译的内容:

How can I ensure my package can be installed without network access (supposing that all dependencies are already resolved)?

如何确保我的包可以在没有网络访问的情况下安装(假设所有依赖关系都已解决)?

By having built a wheel out of it, and installing the wheel on the desert island machine.

通过制作一个wheel,然后在荒岛机器上安装该wheel。

If your package is PEP 517 compliant, use build:

如果您的包符合PEP 517标准,请使用build

(buildbox) $ python -m build .
# whisk dist/*.whl to your isolated machine
(isolated) $ pip install ./*.whl

您还可以使用pip下载其余的依赖关系wheel(只要您的目标机器与使用的体系结构等相同),例如,对于使用scikit-learn的情况:

Saved /scikit_learn-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /joblib-1.2.0-py3-none-any.whl
Saved /numpy-1.24.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /scipy-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /threadpoolctl-3.1.0-py3-none-any.whl

通过评论:

如果确实需要从源代码构建,可以选择:

  • 使用--find-links将开发依赖项作为wheels进行打包,以便Pip可以将它们安装到隔离的构建环境中,或者
  • 设置--no-build-isolation,以便Pip不会创建单独的构建环境,而是使用环境中的构建依赖项。
英文:

> How can I ensure my package can be installed without network access (supposing that all dependencies are already resolved)?

By having built a wheel out of it, and installing the wheel on the desert island machine.

If your package is PEP 517 compliant, use build:

(buildbox) $ pip install build
(buildbox) $ python -m build .
# whisk dist/*.whl to your isolated machine
(isolated) $ pip install ./*.whl

You can also use pip to download the rest of the dependency wheels (so long as you're using the same architecture, etc. as the target machine) – e.g. for something that uses scikit-learn:

$ pip download ./*.whl
Saved /scikit_learn-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /joblib-1.2.0-py3-none-any.whl
Saved /numpy-1.24.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /scipy-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /threadpoolctl-3.1.0-py3-none-any.whl

Via the comments:

If you absolutely do need to build from source, either

  • ship the development dependencies as wheels and use --find-links so Pip can install them into the isolated build environment, or
  • set --no-build-isolation so Pip doesn't create a separate build environment, and uses the ambient build dependencies.

huangapple
  • 本文由 发表于 2023年3月3日 22:59:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定