TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How To Package Your Python Code

157 点作者 storborg超过 12 年前

12 条评论

gvalkov超过 12 年前
I've wondered why using a dictionary to initialize <i>setuptools.setup()</i> isn't more advocated in such guides. I understand this is superficial, but imho, this looks much clearer than the author's suggestion [1]:<p><pre><code> from setuptools import setup kw = { 'name' : 'funniest', 'version' : '0.1', 'description' : 'The funniest joke in the world', 'url' : 'http://github.com/storborg/funniest', 'author' : 'Flying Circus', 'author_email' : 'flyingcircus@example.com', 'license' : 'MIT', 'packages' : ['funniest'], 'zip_safe' : False, } if __name__ == '__main__': setup(**kw) </code></pre> Here are a few of my <i>setup.py</i> files that follow this convention [2] [3] [4].<p>[1]: <a href="http://www.scotttorborg.com/python-packaging/minimal.html#creating-the-scaffolding" rel="nofollow">http://www.scotttorborg.com/python-packaging/minimal.html#cr...</a><p>[2]: <a href="https://github.com/gvalkov/harstats-graphite/blob/master/setup.py" rel="nofollow">https://github.com/gvalkov/harstats-graphite/blob/master/set...</a><p>[3]: <a href="https://github.com/gvalkov/jenkins-autojobs/blob/master/setup.py" rel="nofollow">https://github.com/gvalkov/jenkins-autojobs/blob/master/setu...</a><p>[4]: <a href="https://github.com/gvalkov/python-evdev/blob/master/setup.py" rel="nofollow">https://github.com/gvalkov/python-evdev/blob/master/setup.py</a>
评论 #4802157 未加载
评论 #4801954 未加载
JulianWasTaken超过 12 年前
Taking a quick look through this it looks pretty good! I find that beginners have tons of trouble navigating the slightly tricky waters that is packaging in Python, so more resources is great.<p>One thing I think is missing is to point out <i></i>not<i></i> to use setuptools, but to use the less broken, more maintained, drop in replacement distribute (<a href="http://guide.python-distribute.org/" rel="nofollow">http://guide.python-distribute.org/</a>). That website also has some further information on the packaging ecosystem that's worth flipping through.
评论 #4801895 未加载
评论 #4801990 未加载
pak超过 12 年前
The fact that there is no good, canonical guide for doing this in Python is one of the reasons I moved away from it and toward Ruby. With Ruby I had no problems writing and forking gems using the canonical guide (<a href="http://guides.rubygems.org/make-your-own-gem/" rel="nofollow">http://guides.rubygems.org/make-your-own-gem/</a>). With Python, navigating the hell that is packaging is just demoralizing when it comes time to give end users a complicated chunk of code. (Setuptools is truly "a hack on a top of a bad design", not my own words.) I hope for Python's own sake that distribute (<a href="http://packages.python.org/distribute/" rel="nofollow">http://packages.python.org/distribute/</a>) catches on and people are simply shamed out of using older tools, but since Python already has a problem with getting everyone to migrate code away from old things, I'm not holding my breath.<p>I'm still not sure how to do certain things "right", e.g., distribute a modified version of somebody else's package with my own package. In Ruby, I can do this with bundler specifying a git repo for my own fork of the gem (and then submit a pull request for the original fork, if it's a patch that's useful upstream).
评论 #4808177 未加载
chewxy超过 12 年前
Here are other good packaging guides for Python (by Tarek Ziade). I think Scott Torbog has joined the ranks of these greats:<p><a href="http://www.aosabook.org/en/packaging.html" rel="nofollow">http://www.aosabook.org/en/packaging.html</a><p><a href="http://guide.python-distribute.org/" rel="nofollow">http://guide.python-distribute.org/</a>
mixedbit超过 12 年前
Are setuptools suitable for packaging the whole web application (for example in Django) together with html/js/css files, configs for uwsgi and some management scripts?<p>I once tried to do something like this and failed and I had an impression that setuptools are not really intended for such things, but mainly for packaging plain Python modules.<p>Is this a right impression? If yes, what is a good way to package the whole Python based web application?
评论 #4803265 未加载
评论 #4801995 未加载
评论 #4802048 未加载
feniv超过 12 年前
I know this isn't exactly related to packaging the code, but any thoughts on utilities like py2exe (<a href="http://www.py2exe.org/" rel="nofollow">http://www.py2exe.org/</a>), cx_Freeze (<a href="http://cx-freeze.sourceforge.net/" rel="nofollow">http://cx-freeze.sourceforge.net/</a>) or pyinstaller (<a href="http://www.pyinstaller.org/" rel="nofollow">http://www.pyinstaller.org/</a>) for distributing finished python modules to end-users?
rhettg超过 12 年前
You guys might also find this github project useful: <a href="https://github.com/splaice/py-bootstrap" rel="nofollow">https://github.com/splaice/py-bootstrap</a>
maxjaderberg超过 12 年前
ive been writing python for ages but never found a simple introduction to how to package modules - always thought it was voodoo, so thanks a lot! so simple...
评论 #4804540 未加载
dearmash超过 12 年前
I apologize for the spam, but apparently I'm unable to save articles for some reason. I'd like to read this later, and I want to see if a comment will work.
评论 #4804040 未加载
borntyping超过 12 年前
While I've already been doing things a similar way, it's nice to have a clean, clear explanation of how to package stuff.
norlowski超过 12 年前
Awesome job. I had been stressing about getting my code up there but your tutorial made it easy.
phryk超过 12 年前
Thanks, this is exactly what I was looking for the last few weeks and couldn't find :)