5

I'm not happy with the way that I currently deploy Python code and I was wondering if there is a better way. First I'll explain what I'm doing, then the drawbacks:

  • When I develop, I use virtualenv to do dependancy isolation and install all libraries using pip. Python itself comes from my OS (Ubuntu)
  • Then I build my code into a ".deb" debian package consisting of my source tree and a pip bundle of my dependancies
  • Then when I deploy, I rebuild the virtualenv environment, source foo/bin/activate and then run my program (under Ubuntu's upstart)

Here are the problems:

  1. The pip bundle is pretty big and increases the size of the debian package significantly. This is not too big a deal, but it's annoying.
  2. I have to build all the C libraries (PyMongo, BCrypt, etc) every time I deploy. This takes a little while (a few minutes) and it's a bit lame to do this CPU bound job on production

Here are my constraints:

  1. Must work on Python 3. Preferably 3.2
  2. Must have dependency isolation
  3. Must work with libraries that use C (like PyMongo)

I've heard things about freezing, but I haven't been able to get this to work. cx_freeze out of Pypi doesn't seem to compile (on my Python, at least). The other freeze utilities don't seem to work with Python 3. How can I do this better?

4

2 回答 2

1

Wheel可能是目前最好的方法。

在部署机器上创建一个虚拟环境,并将一个轮子连同任何依赖项(也构建为轮子)部署到该虚拟环境。

这解决了以下问题:

  1. 为依赖项使用单独的轮子意味着您不必重新部署未更改的依赖项,从而减少部署工件的大小
  2. 可以在本地构建大包(例如lxml或scipy),然后将编译好的轮子推送到生产中

此外,它适用于使用 C 的库。

于 2013-06-01T22:49:20.100 回答
0

你看过buildout(zc.buildout)吗?使用自定义配方,您可以自动完成大部分操作。

于 2012-12-02T17:47:20.913 回答