gpt4 book ai didi

python - 在 Python 轮子中包含运行时依赖项

转载 作者:太空狗 更新时间:2023-10-29 18:02:59 25 4
gpt4 key购买 nike

我想分发整个 virtualenv,或者一堆具有运行时依赖性的精确版本的 Python wheels,例如:

  • pycurl
    • pycurl.so
      • libcurl.so
        • libz.so
        • libssl.so
        • libcrypto.so
        • libgssapi_krb5.so
          • libkrb5.so
            • libresolv.so

我想我可以依靠系统安装 libssl.so,但肯定不是正确版本的 libcurl.so,也可能不是 Kerberos。

将一个库与所有运行时依赖项打包到一个 wheel 中的最简单方法是什么?

或者这是傻瓜的差事,我应该打包整个 virtualenv?如何可靠地做到这一点?

附言即时编译不是一种选择,一些模块已打补丁。

最佳答案

据我所知,没有好的标准方法可以移植地安装包的依赖项。 Continuum 有 made conda for precisely this purpose . numpy 的家伙在他们的包中编写了他们自己的 distutils 子模块来安装一些复杂的依赖项,现在 at least some of them advocate conda as a solution .不幸的是,您可能必须自己为其中一些依赖项制作 conda 包。

如果没有可移植性你没问题,那么以目标机器的包管理器为目标显然会起作用。否则,对于可移植包管理器,conda 是我所知道的唯一选择。

或者,从您的帖子(“即时编译不是一种选择”)听起来可移植性对您来说可能不是问题,在这种情况下您还可以将所有要求安装到前缀目录(我遇到的大多数安装程序都支持 configure --prefix=/some/dir/ 选项)。如果您有一个有保证的单一架构,您可能可以将所有依赖项预先安装到一个目录中,然后像文件一样传递它。 conda 方法可能更简洁,但我已经使用了相当多的前缀安装,它们往往是最容易上手的解决方案之一。

编辑:至于 conda,它同时是一个包管理器和一个类似“virtualenv”的环境/python 安装。虽然 virtualenv 添加在现有 python 安装之上,但 conda 接管了整个安装,因此您可以更加确定所有依赖项都已考虑在内。与 pip 相比,它旨在添加通用的非 Python 依赖项,而不仅仅是编译 C/Cpp 扩展。有关更多信息,我会看到:

至于如何根据您的目的使用 conda,the docs解释如何创建食谱:

Conda build framework

Building a package requires a recipe. A recipe is flat directory which contains the following files:

  • meta.yaml (metadata file)
  • build.sh (Unix build script which is executed using bash)
  • bld.bat (Windows build script which is executed using cmd)
  • run_test.py (optional Python test file)
  • patches to the source (optional, see below)
  • other resources, which are not included in the source and cannot be generated by the build scripts.

The same recipe should be used to build a package on all platforms.

When building a package, the following steps are invoked:

  1. read the metadata
  2. download the source (into a cache)
  3. extract the source in a source directory
  4. apply the patches
  5. create a build environment (build dependencies are installed here)
  6. run the actual build script. The current working directory is the source directory with environment variables set. The build script installs into the build environment
  7. do some necessary post processing steps: shebang, rpath, etc.
  8. add conda metadata to the build environment
  9. package up the new files in the build environment into a conda package
  10. test the new conda package:
    • create a test environment with the package (and its dependencies)
    • run the test scripts

There are example recipes for many conda packages in the conda-recipes
<https://github.com/continuumio/conda-recipes>
_ repo.

The :ref:conda skeleton <skeleton_ref> command can help to make skeleton recipes for common repositories, such as PyPI <https://pypi.python.org/pypi>_.

然后,作为客户端,您将安装包 similar to how you would install from pip

最后,docker您可能也很感兴趣,尽管我还没有看到它在 Python 中的应用。

关于python - 在 Python 轮子中包含运行时依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26019920/

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