如何打包 python 应用程序以使其可 pip 安装? [英] How do I package a python application to make it pip-installable?

查看:20
本文介绍了如何打包 python 应用程序以使其可 pip 安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

我所做的假设是 MANIFEST.insetup.py 是 pip 完成其工作所需的唯一必需部分.那是对的吗?如果我的假设是错误的,还需要哪些其他组件?

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?

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

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?

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

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?

推荐答案

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

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

这篇博文确实有一些关于这个主题的好信息:打包一个 Django 可重用应用

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

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

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.

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

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

例如:

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

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

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

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

With this setup your package should be installable via pip.

正如 Pierre 在评论中指出的,现在 Django 的官方文档中还有一个相关部分:打包你的应用

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

然后是这个完全不完整"的指南,它对打包和上传包到 PyPI 给出了很好的概述:分享你爱的劳动:PyPI Quick And Dirty

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

这篇关于如何打包 python 应用程序以使其可 pip 安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆