在pythonwheels中包含运行时依赖项

2024-09-30 01:33:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我想发布一个完整的virtualenv,或者一堆精确版本的Python轮子及其运行时依赖关系,例如:

  • 卷曲
    • 在pycurl.所以
      • 在libcurl.so
        • 在利伯兹·索在
        • 在libssl.so文件在
        • 在libcrypto.so在
        • 利布萨皮•克鲁5.so
          • libkrb5.so
            • 在libresolv.so公司在

我想我可以依靠这个系统libssl.so文件安装了,但肯定没有libcurl.so可能不是Kerberos。在

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

或者这是一个愚蠢的差事,我应该打包整个虚拟机? 如何可靠地做到这一点?在

p.S.动态编译不是一个选项,有些模块是修补的。在


Tags: 文件版本sovirtualenv关系系统公司轮子
2条回答

你可能想看看PEX:https://pex.readthedocs.io/en/stable/whatispex.html

扩展名为.pex的文件-“pex文件”或“.pex文件”是自包含的可执行Python虚拟环境。PEX文件使Python应用程序的部署变得容易:部署过程变得简单的scp

事实上,没有一种好的标准方法可以移植地安装软件包的依赖项。连续体有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中有多少使用。在

相关问题 更多 >

    热门问题