Python setup.py:在安装过程中询问配置数据
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.