Buildout and Virtualenv

buildout, python, virtualenv

Solution

You don't need virtualenv: buildout already provides an isolated environment, just like virtualenv.

As an example, look at files buildout generates in the bin directory. They'll have something like:

import sys
sys.path[0:0] = [
     '/some/thing1.egg',
     # and other things
     ]

So the `sys.path` gets completely replaced with what buildout wants to have on the path: the same isolation method as virtualenv.

Problem

I am messing around with the combination of buildout and virtualenv to setup an isolated development environment in python that allows to do reproducible builds. There is a recipe for buildout that let's you integrate virtualenv into buildout: ``` tl.buildout_virtual_python ``` With this my buildout.cfg looks like this: ``` [buildout] develop = . parts = script virtualpython [virtualpython] recipe = tl.buildout_virtual_python headers = true executable-name = vp site-packages = false [script] recipe = zc.recipe.egg:scripts eggs = foo python = virtualpython ``` This will deploy two executables into ./bin/: ``` vp script ``` When I execute vp, I get an interactive, isolated python dialog, as expected (can't load any packages from the system). What I would expect now, is that if I run ``` ./bin/script ``` that the isolated python interpreter is used. But it doesn't, it's not isolated as "vp" is (meaning I can import libraries from system level). However I can run: ``` ./bin/vp ./bin/script ``` Which will run the script in an isolated environment as I wished. But there must be a way to specify this to do so without chaining commands otherwise buildout only solves half of the problems I hoped :) Thanks for your help! Patrick

Original source