Python setup.py:在安装过程中询问配置数据

发布于 2025-01-04 04:15:29 字数 812 浏览 3 评论 0原文

我使用 PIP 打包我的 Python 应用程序,提供 setup.py。 在安装过程中,我想询问用户几个值(用户名、其他配置值),然后将这些值保存在用户目录中存储的应用程序配置文件中。

在安装过程中是否有特殊的 PIP/distutils-way 来询问这些配置值? 或者我应该只使用 input 来询问用户,如下所示:

#!/usr/bin/env python

from distutils.core import setup

cfg['name'] = input("Please your username:")
cfg.save()

setup(name='appname',
      version='1.0',
      description='App Description',
      author='Author',
      author_email='[email protected]',
      packages=['mypackage'],
     )

或者我应该不询问这些值,而是让用户在第一次启动时配置应用程序?

我知道所有这些方法都是可能的,但是有没有任何约定或最佳实践?或者你知道有一个流行的 Python 项目在做类似的事情,这是一个很好的例子吗?

I package my Python application with PIP, providing a setup.py.
During installation, I want to ask the user for several values (user name, other configuration values), these values are then saved inside the application configfile stored inside the user directory.

Is there a special PIP/distutils-way to ask for these configuration values during setup?
Or should I just use input to ask the user, like this:

#!/usr/bin/env python

from distutils.core import setup

cfg['name'] = input("Please your username:")
cfg.save()

setup(name='appname',
      version='1.0',
      description='App Description',
      author='Author',
      author_email='[email protected]',
      packages=['mypackage'],
     )

Or should I leave out asking for these values, and instead let the user configure the application on the first start?

I know that all of these ways are possible, but are there any conventions or best practices for that? Or do you know of a popular Python project doing similar stuff which is a good example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳哥哥 2025-01-11 04:15:29

setup.py 为您提供了非常原始的界面来安装 python 包。您可以使用 配置文件 或为您的应用程序创建一些 GUI 安装程序。

另一种方法是为您的应用程序构建依赖于操作系统的软件包(Windows 的 deb、rpm、msi)。

setup.py provides you very primitive interface to install python packages. You can use a config file or create some GUI installer for your application.

Another way is to build OS depended packages (deb, rpm, msi for Windows) for your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文