分发 Python 库(单个文件)

发布于 2024-09-02 22:28:33 字数 198 浏览 2 评论 0原文

对于我的项目,我将使用 argparse 库。我的问题是,如何将它分发到我的项目中。我问这个问题是因为涉及技术细节和合法性。

我只是:

  1. 将 argparse.py 文件与 我的项目。也就是说,在我的项目的 tar 文件中。
  2. 为我的它创建一个包 发行版?
  3. 让用户自己安装?

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:

  1. Put the argparse.py file along with
    my project. That is, in the tar file for my project.
  2. Create a package for it for my
    distro?
  3. Tell the user to install it himself?

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

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

发布评论

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

评论(3

薄荷→糖丶微凉 2024-09-09 22:28:33

你的目标 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.

雪化雨蝶 2024-09-09 22:28:33

用户最好安装它,以便系统上只存在一个副本,以便在出现任何问题时可以更新它,但如果您遵守指定的所有要求,则将其包含在您的项目中是一个可行的选择在许可证中。

尝试从公共位置导入它,如果失败,则诉诸使用包含的模块。

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.

旧街凉风 2024-09-09 22:28:33

你可以采纳伊格纳西奥的建议。

但是……就其价值而言,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!

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