python 依赖和部署工具?

5 投票
2 回答
1541 浏览
提问于 2025-04-16 18:09

有没有人知道有什么工具可以处理Python中的模块依赖和部署?

具体来说,我想要的功能是:

  • 列出所有模块,
  • 跟踪这些模块的状态,
  • 把它们打包成一个可以安装的zip文件。
  • 让我在其他系统上重新部署时变得简单(也就是说:在部署文件中包含所有模块的正确版本,不需要去其他地方下载它们*)。
  • 如果我快要做一些会改变环境的事情,能提醒我。
  • 必须能追踪所有模块的依赖关系,而不仅仅是第一层的依赖。
  • 还有一些我可能没想到的功能。

  • 我不是在说Virtualenv、Fabric、pip freeze**和(我认为)Paver。

今晚我试着数了一下Pylons依赖的模块。经过一番折腾用Snakefood和Graphviz,结果是很多,超过100个(而且Snakefood并没有找到所有的模块)。

随着我越来越深入学习Python,手动处理这个问题开始占用我更多的时间,而且还不太可靠。

如果有关系的话,我在Windows 7上使用Python 2.7。

* I know this will introduce some artifacts.  
** Combining virtualenv and pip freeze goes some way to solving this, but it's still not what I am looking for. 

2 个回答

5

Setuptoolspypi 是为这个目的而设计的。Setuptools 是对 distutils 的一种增强工具,使用它你可以指定你的程序需要哪些其他工具或库。比如,在设置函数中:

install_requires = ['simplejson>=2.0,==dev'],

当你使用 easy_install 时,它会自动下载并安装这些依赖的工具。

2

因为你在使用Windows系统,可以看看py2exe这个工具。这里有一些来自py2exe的常见问题解答中有趣的信息:

How does py2exe decide which modules you need?
To determine which modules should go in the final .exe file, py2exe 
does a recursive search of the script that you are packaging to find 
its dependencies and, in turn, all of their dependencies.

撰写回答