分发 Python 库(单个文件)
对于我的项目,我将使用 argparse 库。我的问题是,如何将它分发到我的项目中。我问这个问题是因为涉及技术细节和合法性。
我只是:
- 将 argparse.py 文件与 我的项目。也就是说,在我的项目的 tar 文件中。
- 为我的它创建一个包 发行版?
- 让用户自己安装?
For my project I would be using the argparse library. My question is, how do I distribute it with my project. I am asking this because of the technicalities and legalities involved.
Do I just:
- Put the argparse.py file along with
my project. That is, in the tar file for my project. - Create a package for it for my
distro? - Tell the user to install it himself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的目标 Python 版本是什么?似乎
argparse
包含在版本 2.7 中。如果您正在构建一个具有最少依赖项的小型库,我会考虑删除对外部模块的依赖项,并仅使用标准 Python 库提供的设施。您可以使用 sys.argv 访问命令行参数并自己解析它们,这通常并不难做到。您的用户肯定会喜欢不必安装另一个第三方模块就可以使用您的代码。
What's your target Python version? It appears that
argparse
is included from version 2.7.If you're building a small library with minimal dependencies, I would consider removing the dependency on an external module and only use facilities offered by the standard Python library. You can access command line parameters with
sys.argv
and parse them yourself, it's usually not that hard to do. Your users will definitely appreciate not having to install yet another third party module just to use your code.用户最好安装它,以便系统上只存在一个副本,以便在出现任何问题时可以更新它,但如果您遵守指定的所有要求,则将其包含在您的项目中是一个可行的选择在许可证中。
尝试从公共位置导入它,如果失败,则诉诸使用包含的模块。
It would be best for the user to install it so that only one copy is present on the system and so that it can be updated if there are any issues, but including it with your project is a viable option if you abide by all requirements specified in the license.
Try to import it from the public location, and if that fails then resort to using the included module.
你可以采纳伊格纳西奥的建议。
但是……就其价值而言,Python 中内置了另一个用于参数解析的库,该库非常强大。您是否尝试过 optparse ?它属于基本的 Python 发行版,并且已经存在了一段时间......
祝你好运!
You could go with Ignacio's suggestion.
But... For what it is worth, there's another library for argument parsing built into Python, which is quite powerful. Have you tried optparse? It belongs to the base Python distribution and has been there for a while...
Good luck!