具有操作系统特定依赖性的pip软件包 [英] pip package with OS specififc dependency

查看:83
本文介绍了具有操作系统特定依赖性的pip软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个依赖于某些操作系统特定文件的pip包:

I want to create a pip package which dependent on some OS specific files:

假设有:

  • dependency_Windows_x86_64.zip
  • dependency_Linux_x86_64.zip
  • dependency_MAC_OS_X.zip
  • dependency_Windows_x86_64.zip
  • dependency_Linux_x86_64.zip
  • dependency_MAC_OS_X.zip

我不想在软件包项目中包含所有三个档案,而是在pip install my-package期间根据用户的操作系统动态下载它们.我怎样才能做到这一点 ?我应该将负责下载/解压缩这些文件的代码放在哪里?

I do not want to include all three archives in a package project, but download them dynamically during the pip install my-package based on user's OS. How can I do that ? Where should I put the code responsible for downloading/unzipping those files ?

我的 setup.py 看起来像这样:

from setuptools import setup 

setup(
  name='my-package',
  version='0.0.1',
  description='Package description',
  py_modules=['my_package'],
  package_dir={'': 'src'},
  classifiers=[
    'Intended Audience :: Developers',
    'License :: OSI Approved :: MIT License',
    'Operating System :: POSIX :: Linux',
    'Operating System :: Microsoft :: Windows',
    'Operating System :: MacOS',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.7'
  ],
  python_requires='>=3.7'
)

推荐答案

特定于平台的依赖项可以保存在单独的Python项目(仅数据包中的包装器)中,然后从主项目中进行以下要求:

The platform specific dependencies could be kept in separate Python projects (wrappers around data only packages) and then required from the main project like the following:

# setup.cfg
# ...
[options]
install_requires =
    my_package_win_amd64 ; platform_system=="Windows" and platform_machine=="x86_64"
    my_package_linux-x86_64 ; platform_system=="Linux" and platform_machine=="x86_64"

这种方法不依赖于 setuptools ,可以与其他构建系统一起使用.

This approach doesn't depend on setuptools and could be used with other build systems.

这篇关于具有操作系统特定依赖性的pip软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆