3

I'm working by myself right now, but am looking at ways to scale my operation.

I'd like to find an easy way to version my Python distribution, so that I can recreate it very easily. Is there a tool to do this? Or can I add /usr/local/lib/python2.7/site-packages/ (or whatever) to an svn repo? This doesn't solve the problems with PATHs, but I can always write a script to alter the path. Ideally, the solution would be to build my Python env in a VM, and then hand copies of the VM out.

How have other people solved this?

BenDundee
  • 4,389
  • 3
  • 28
  • 34
  • Why would you want to version control installed libraries? Backup, sure, but version control? –  Jul 12 '13 at 19:55
  • Maybe "version" is the wrong word. The end goal, though, is to have a portable instance of Python that I can give to a colleague, and that they can install with little difficulty, so they can be up and running quickly. – BenDundee Jul 12 '13 at 19:56

3 Answers3

5

virtualenv + requirements.txt are your friend.

You can create several virtual python installs for your projects, everything containing exactly those library versions you need (Tip: pip freeze spits out a requirements.txt with the exact library versions).

Find a good reference to virtualenv here: http://simononsoftware.com/virtualenv-tutorial/ (it's from this question Comprehensive beginner's virtualenv tutorial?).

Alternatively, if you just want to distribute your code together with libraries, PyInstaller is worth a try. You can package everything together in a static executable - you don't even have to install the software afterwards.

Community
  • 1
  • 1
Gregor
  • 4,306
  • 1
  • 22
  • 37
  • Well, the goal is to have an environment that other developers can use, so I'm not sure I want PyInstaller. I'll check out vitualenv--I've heard of it, but have never really investigated it closely. – BenDundee Jul 12 '13 at 20:06
  • In my opinion, there is no way around virtualenv if you are developing python in a team. When it comes to deployment (name a few: Heroku, Engine Yard, ...) - everything is about recreating a python library state. I've added the PyInstaller remark because of your comment of "installing + getting it up and running quickly". – Gregor Jul 12 '13 at 20:09
5

You want to use virtualenv. It lets you create an application(s) specific directory for installed packages. You can also use pip to generate and build a requirements.txt

Jonathan Vanasco
  • 15,111
  • 10
  • 48
  • 72
0

For the same goal, i.e. having the exact same Python distribution as my colleagues, I tried to create a virtual environment in a network drive, so that everybody of us would be able to use it, without anybody making his local copy. The idea was to share the same packages installed in a shared folder. Outcome: Python run so unbearably slow that it could not be used. Also installing a package was very very sluggish.

So it looks there is no other way than using virtualenv and a requirements file. (Even if unfortunately often it does not always work smoothly on Windows and it requires manual installation of some packages and dependencies, at least at this time of writing.)

Apperò
  • 41
  • 7