<p><strong>先读这个</strong><a href="https://packaging.python.org/en/latest/current.html" rel="nofollow noreferrer">https://packaging.python.org/en/latest/current.html</a></p>
<blockquote>
<h1>Installation Tool Recommendations</h1>
<ol>
<li>Use pip to install Python packages
from PyPI. </li>
<li>Use virtualenv, or pyvenv to isolate application specific dependencies from a shared Python installation. </li>
<li>Use pip wheel to create a cache of wheel distributions, for the purpose of > speeding up subsequent installations. </li>
<li>If you’re looking for management of fully integrated cross-platform software stacks, consider buildout (primarily focused on the web development community) or Hashdist, or conda (both primarily focused on the scientific community). </li>
</ol>
<h1>Packaging Tool Recommendations</h1>
<ol>
<li>Use setuptools to define projects and create Source Distributions.</li>
<li>Use the bdist_wheel setuptools extension available from the wheel project to create wheels. This is especially beneficial, if your project contains binary extensions.</li>
<li>Use twine for uploading distributions to PyPI.</li>
</ol>
</blockquote>
<hr/>
<p>这个anwser已经过时了,而且确实有一个针对python打包世界的救援计划,叫做</p>
<h2>轮距</h2>
<p>我想<a href="http://pythonwheels.com/" rel="nofollow noreferrer">pythonwheels.com</a>这里:</p>
<blockquote>
<p><strong>What are wheels?</strong></p>
<p>Wheels are the new standard of python distribution
and are intended to replace eggs. Support is offered in pip >= 1.4 and
setuptools >= 0.8.</p>
</blockquote>
<p>车轮的优点</p>
<ol>
<li>纯python和本机C扩展包的安装速度更快。</li>
<li>避免安装时执行任意代码。(避免setup.py)</li>
<li>在Windows上安装C扩展不需要编译器
或者OS X</li>
<li>允许更好的缓存以进行测试和连续
整合。</li>
<li>在安装过程中创建.pyc文件以确保
它们与使用的python解释器匹配。</li>
<li>跨平台和计算机的安装更加一致。</li>
</ol>
<p>关于正确的python打包(以及关于wheels)的全部内容,请参见<a href="https://packaging.python.org/en/latest/distributing.html" rel="nofollow noreferrer">packaging.python.org</a></p>
<hr/>
<h2>康达路</h2>
<p>对于科学计算(这在packaging.python.org上也是推荐的,见上文),我会考虑使用<a href="http://conda.pydata.org/docs/" rel="nofollow noreferrer">CONDA packaging</a>,这可以看作是在PyPI和pip工具之上构建的第三方服务。它还可以很好地设置您自己的<a href="https://binstar.org/" rel="nofollow noreferrer">binstar</a>版本,因此我可以想象它可以完成复杂的定制企业包管理的技巧。</p>
<p>Conda可以安装到用户文件夹中(没有超级用户权限),工作方式类似于magic</p>
<blockquote>
<p>conda install </p>
</blockquote>
<p>以及强大的虚拟环境扩展。</p>
<hr/>
<h2>鸡蛋道</h2>
<p><em>此选项与python-distribute.org相关,并且已经过时(以及站点),因此让我向您介绍一个我喜欢的现成且紧凑的setup.py示例:</em></p>
<ul>
<li>将脚本和单个python文件混合到setup.py中的一个非常实用的示例/实现给出了<a href="https://stackoverflow.com/questions/10458158/python-setup-py-configuration-to-install-files-in-custom-directories">here</a></li>
<li>更棒的是<a href="https://github.com/hyperopt/hyperopt-convnet/blob/master/setup.py" rel="nofollow noreferrer">hyperopt</a></li>
</ul>
<p>这段引述摘自setup.py的<strong>状态指南,仍然适用:</p>
<ul>
<li>setup.py不见了!</li>
<li>distutils不见了!</li>
<li>分发出去!</li>
<li>皮普和维图阿列夫留在这里!</li>
<li>鸡蛋。。。跑了!</li>
</ul>
<p>我(向我)再加一点</p>
<ul>
<li><strong>车轮</strong>!</li>
</ul>
<p><strike>我建议在尝试无意识的复制粘贴之前,先了解一下<a href="http://guide.python-distribute.org/introduction.html#the-packaging-ecosystem" rel="nofollow noreferrer">packaging-ecosystem</a>(来自gotgenes所指的指南)。</strike></p>
<p>互联网上的大多数例子都是从</p>
<pre><code>from distutils.core import setup
</code></pre>
<p>但是这个示例不支持构建egg<strong>python setup.py bdist_egg</strong>(以及其他一些<em>旧的</em>功能),这些功能在</p>
<pre><code>from setuptools import setup
</code></pre>
<p>原因是它们已被弃用。</p>
<p>现在根据指南</p>
<blockquote>
<p>Warning</p>
<p>Please use the Distribute package rather than the Setuptools package
because there are problems in this package that can and will not be
fixed.</p>
</blockquote>
<p>不推荐使用的setuptools将被<a href="http://alexis.notmyidea.org/distutils2/tutorial.html" rel="nofollow noreferrer">distutils2</a>替换,后者“将成为Python 3.3中标准库的一部分”。我必须说我喜欢安装工具和鸡蛋,但还没有完全相信distutils2的便利性。它需要</p>
<pre><code>pip install Distutils2
</code></pre>
<p>以及安装</p>
<pre><code>python -m distutils2.run install
</code></pre>
<p/>
<h2>聚苯乙烯</h2>
<p>包装从来都不是小事(一个人通过尝试开发一个新的来学习这个),所以我认为很多事情都是有原因的。我只希望这次它能正确地完成。</p>