Python:根据要求.txt在runtim

2024-05-28 23:04:55 发布

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

我有一个带有命令行脚本的Python应用程序。我通过setuptools“入口点”特性公开脚本。每当用户运行脚本时,我希望环境与包的requirements.txt保持一致。这意味着环境必须包含与requirements.txt中的版本说明符匹配的每个依赖项包的版本。在

我知道这可以通过venv/virtualenv实现,方法是让我的用户创建一个虚拟环境,在其中安装requirements.txt,并在每次运行脚本时激活该虚拟环境。我不想把手动调用virtualenv的负担强加给用户。Ruby的bundler通过提供bundler/setup来解决这个问题——在加载时,它修改Ruby的$LOAD_PATH,以反映{}(类似于requirements.txt)的内容。因此,它可以放在脚本的顶部,以透明地控制运行时环境。Python有等价物吗?也就是说,在运行时根据requirements.txt设置环境,而不给用户增加额外的复杂性?在


Tags: 命令行用户版本txt脚本应用程序环境virtualenv
2条回答

我不明白为什么Python程序在导入它们之前不可能安装自己的依赖项,但是在Python社区中这是闻所未闻的。在

我更愿意考虑让应用程序成为独立可执行文件的选项,例如here。在

Does Python have an equivalent? That is, a way to set the environment at runtime according to requirements.txt without imposing additional complexity on the user?

是的,不止一个。在

一个是pex

pex is a library for generating .pex (Python EXecutable) files which are executable Python environments in the spirit of virtualenvs.

另一个是Platter

Platter is a tool for Python that simplifies deployments on Unix servers. It’s a thin wrapper around pip, virtualenv and wheel and aids in creating packages that can install without compiling or downloading on servers.

相关问题 更多 >

    热门问题