如何打包python应用程序以使其可以管道安装? [英] How do I package a python application to make it pip-installable?
问题描述
我要包装零件。很多GitHub上的django应用程序大多是捆绑的(大致)相同的方式。我将以 django-uni-forms 为例。
我所做的一个假设是, MANIFEST.in
和 setup.py
是需要完成工作的唯一需要的部分。那是对的吗?如果我的假设是错误的,还需要哪些其他组件?
所需的打包文件是否通常生成或手工制作?可以依赖关系进行描述,然后再安装?我的应用程序取决于 django-uni-forms
,我将其列在我的应用程序中的 requires.txt
文件中我用来安装依赖;但是这是包装系统可以照顾的东西吗?
我需要遵循的步骤来打包我的应用程序,以便点数能够安装它和任何依赖关系?
是, MANIFEST.in
setup.py
应该是足够的。
这篇博文真的有一些关于这个话题的好的信息:
打包Django可重复使用的应用
这是另一个很好的详细的概述,帮助我很多:
Python包装用户指南
特别是包含静态文件(模板)的提示很重要,因为这可能不明显。
是的,您可以在安装应用程序时自动获取的 setup.py
中指定所需的软件包。 p>
例如:
install_requires = [
'django-个人资料',
'django-uni-forms',
],
显然现在我们有两个地方定义了依赖关系,但并不一定意味着这些信息是重复的:设置.py vs requirements.txt
使用此设置,您的软件包应通过 pip
。
正如Pierre在评论中指出的那样,Django的官方文档中还有一个相关的部分:打包您的应用
然后有这个完全不完整的指南,真正给了包装和上传包裹到PyPI:分享你的劳动:PyPI快速和脏a>
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?
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
这篇关于如何打包python应用程序以使其可以管道安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!