有没有办法为我的基于平台的 Python 应用程序提供一个有条件的 requirements.txt 文件?

编程入门 行业动态 更新时间:2024-10-16 00:16:37
本文介绍了有没有办法为我的基于平台的 Python 应用程序提供一个有条件的 requirements.txt 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我编写了一个与 Linux 和 Windows 平台兼容的 Python 应用程序.但是有一个问题......我需要的一个用于 Windows 的 python 包与 Linux 不兼容.幸运的是,还有另一个软件包可以在 Linux 上提供相同的功能.所有其他依赖项在两个平台上都兼容.

I have a python application that I wrote to be compatible with both, Linux and Windows platforms. However there is one problem... One of the python packages I need for Windows is not compatible with Linux. Fortunately there is another package that provides the same functionality on Linux. All other dependencies are compatible in both platforms.

我知道我可以有 2 个单独的需求文件来分别解决两个平台依赖项.类似于 win_requirements.txt 和 linux_requirements.txt 的东西,但是这种方法感觉并不是最好的方法.

I know I could have 2 separate requirement files to address both platform dependencies separately. Something like win_requirements.txt and linux_requirements.txt, however this approach doesn't feel like the best way to do it.

我想知道是否有一种方法可以让我只拥有一个 requirements.txt 文件,以便任何用户都可以使用 pip install -r requirements.txt 来安装所有依赖项,而不管它们是什么平台?

I wonder if there is a way I can have only one requirements.txt file so any user can use pip install -r requirements.txt to install all the dependencies regardless of what platform they are?

也许像??:

SOAPpy>=0.12.22 pycrypto>=2.6.1 suds>=0.4 Python-ldap>=2.4.19 paramiko>=1.15.2 nose>=1.3.4 selenium>=2.44.0 bottle>=0.12.8 CherryPy>=3.6.0 pika>=0.9.14 if platform.system() == 'Linux': wmi-client-wrapper>=0.0.12 else if platform.system() == 'Windows': WMI>=1.4.9

推荐答案

您可以创建一个 install.py 脚本并通过脚本调用 pip.

You could create an install.py script and call pip by script.

import pip _all_ = [ "SOAPpy>=0.12.22", "pycrypto>=2.6.1", "suds>=0.4", "Python-ldap>=2.4.19", "paramiko>=1.15.2", "nose>=1.3.4", "selenium>=2.44.0", "bottle>=0.12.8", "CherryPy>=3.6.0", "pika>=0.9.14", ] windows = ["wmi-client-wrapper>=0.0.12",] linux = ["WMI>=1.4.9",] darwin = [] def install(packages): for package in packages: pip.main(['install', package]) if __name__ == '__main__': from sys import platform install(_all_) if platform == 'windows': install(windows) if platform.startswith('linux'): install(linux) if platform == 'darwin': # MacOS install(darwin)

仅使用 requirements 文件解决此问题的另一种方法应该是使用 requirements

Another way to resolve this issue using only requirements files should be using inheritance of requirements

要求.txt

SOAPpy>=0.12.22 pycrypto>=2.6.1 suds>=0.4 Python-ldap>=2.4.19 paramiko>=1.15.2 nose>=1.3.4 selenium>=2.44.0 bottle>=0.12.8 CherryPy>=3.6.0

windows.txt

windows.txt

-r requirements.txt WMI>=1.4.9

linux.txt

-r requirements.txt WMI>=1.4.9

然后你可以只调用与平台等效的需求.

Then you can call just the requirement equivalent to platform.

pip install -r windows.txt pip install -r linux.txt

更多推荐

有没有办法为我的基于平台的 Python 应用程序提供一个有条件的 requirements.txt 文件?

本文发布于:2023-06-11 14:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/637070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   提供一个   有条件   应用程序   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!