如何打包 python 应用程序以使其可 pip 安装?

发布于 2024-10-24 17:12:39 字数 566 浏览 1 评论 0原文

我正在业余时间为我们在工作中举办的足球小费比赛编写一个 Django 应用程序。我想我应该明智地利用这段时间,快速了解 virtualenv、pip、打包、django 1.3 以及如何编写易于重新分发的应用程序。到目前为止,一切都很好。

我正在处理包装部分。例如,GitHub 上的许多 django 应用程序大多(大致)以相同的方式捆绑。我将使用 django-uni-forms 作为示例。

我所做的假设是 MANIFEST.in 和 setup.py 是 pip 完成其工作所需的唯一部分。这是正确的吗?如果我的假设是错误的,还需要哪些其他组件?

所需的打包文件是一般生成的,还是手工制作的?可以描述依赖关系然后安装吗?我的应用程序依赖于 django-uni-forms,并且我将其列在我用来安装依赖项的应用程序内的 requirements.txt 文件中;但这是包装系统可以处理的事情吗?

我需要遵循哪些步骤来打包我的应用程序,以便 pip 能够安装它和任何依赖项?

I'm writing a django application in my spare time for a footy-tipping competition we're running at work. I figured I'd use this time wisely, and get up to speed on virtualenv, pip, packaging, django 1.3, and how to write an easily redistributable application. So far, so good.

I'm up to the packaging part. A lot of the django apps on GitHub for instance are mostly bundled (roughly) the same way. I'll use django-uni-forms as an example.

An assumption I'm making is that the MANIFEST.in and setup.py are the only required pieces that pip needs to do its job. Is that correct? What other components are necessary if my assumption is wrong?

Are the required packaging files generally generated, or are they crafted by hand? Can dependencies be described and then installed also? My application depends on django-uni-forms, and I have it listed in a requirements.txt file within my app which I used to install the dependency; but is that something that the packaging system can take care of?

What are the steps I need to follow to package my application in such a way that pip will be able to install it and any dependencies?

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

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

发布评论

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

评论(1

茶色山野 2024-10-31 17:12:39

是的,MANIFEST.insetup.py 应该足够了。

这篇博文确实提供了有关该主题的一些很好的信息:
打包 Django 可重用应用程序

这是另一个很好、详细的概述,对我帮助很大:
Python 打包用户指南

特别是包含静态文件(模板)的提示很重要,因为这在以下位置可能并不明显第一的。

是的,您可以在 setup.py 中指定所需的包,这些包在安装应用程序时会自动获取。

例如:

    install_requires = [
        'django-profiles',
        'django-uni-forms',
    ],

显然现在我们有两个定义依赖关系的地方,但这并不一定意味着这些信息是重复的: setup.py 与requirements.txt

通过此设置,您的软件包应该可以通过 安装pip


正如 Pierre 在评论中指出的那样,Django 的官方文档中现在也有一个相关部分: 打包您的应用程序

然后是这个“完全不完整”的指南,它确实很好地概述了打包并将包上传到 PyPI:分享您的爱的劳动:PyPI Quick And Dirty

Yes, MANIFEST.in and setup.py should be sufficient.

This blog post really has some good information on this topic:
Packaging a Django reusable app

And here's another good, detailed overview that helped me a lot:
Python Packaging User Guide

Especially the tips to get your static files (templates) included are important as this might not be obvious at first.

And yes, you can specify required packages in your setup.py which are automatically fetched when installing your app.

For example:

    install_requires = [
        'django-profiles',
        'django-uni-forms',
    ],

Obviously now we have two places where dependencies are defined, but that doesn't necessarily mean that these information are duplicated: setup.py vs requirements.txt

With this setup your package should be installable via pip.


As Pierre noted in the comments, there's now also a relevant section in Django's official documentation: Packaging your app

And then there is this "completely incomplete" guide, which really gives a great overview over packaging and uploading a package to PyPI: Sharing Your Labor of Love: PyPI Quick And Dirty

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