168

I'm a java developer/python beginner, and I'm missing my maven features, particularly dependency management and build automation (I mean you don't build, but how to create a package for deployment?)

Is there a python equivalent to achieve these features?
Note: I use python 2.x

Thanks.

5 Answers 5

82

Python uses distutils and setuptools for dependency and packaging.

Heres a tutorial which explains basics: http://docs.activestate.com/activepython/3.2/diveintopython3/html/packaging.html

In short, you will have setup.py file, which has dependency and script compilation/installation information, and you can build eggs, dist tarballs, binary tarballs, etc with it.

5
  • 7
    Since the dearly electro-departed Mark Pilgrim shut down that site, here is mirror at activestate.
    – jiggy
    Commented Feb 4, 2012 at 20:18
  • 4
    I'd recommend updating this to point to The Python Packaging User Guide since it is the authoritative guide now.
    – kojiro
    Commented May 24, 2016 at 20:16
  • The links in the question, and both comments, are dead. Commented Jan 12, 2021 at 8:15
  • 2
    Working January 2021 link for the Python Packaging User Guide: packaging.python.org
    – jshd
    Commented Jan 23, 2021 at 14:19
  • @RupertMadden-Abbott I was able to access the dead link via Wayback Machine
    – safesploit
    Commented Dec 1, 2022 at 16:01
43

There is no direct match. However, the closest you can get:

  • zc.buildout: It can setup closed environments, download/handle dependencies, initialize scripts, etc. It also builds on plugins (or "recipes", as they call them). I used it a few years ago when it was in beta stages, probably it has evolved since then. There is learning curve, as with Maven, but it's also the most powerful.

Other offerings are subsets of Maven/zc.buildout:

You probably know Ant and shell scripting, so you could check also these Python tools:

  • Fabric or Paver: command-line task runners with added flavors. They wrap your traditional command-line execution in python, and allow to manage various tasks in a more powerful way (task dependencies, interpreting output, running commands in remote server, etc.). Basically nothing you couldn't do with shell scripting, but in python, it's much less cryptic.
17

I'd like to point out PyBuilder which is heavily inspired by maven but uses python instead of XML for configuration, so it's actually readable, IMHO.

There is a plugin for dependency management (uses pip under the hood and differentiates between build and runtime dependencies) and, not unlike maven, you can run through the full build lifecycle with a single command.

1
9

For deployment, in addition to distutils/setuptoos, also take a look at the pip package (uses setuptools underneath). It can rollback failed installations and also uninstall (something missing from easy_install/setuptools). In addition, you can specify dependencies through a requirements text file.

6

It's good to use virtualenv to create standalone project environment and use pip/easy_install to management dependencies.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.