Using VirtualEnv for ZTFY packages installation

Using VirtualEnv is not a pre-requisite to ZTFY packages installation or any other Zope 3 development or production environment.

But using it allows you to isolate your working environment from the rest of your system.

This separated installation allows:

  • to make this installation without risk, as installed packages are not overwriting standard ones already installed on the system
  • to make an installation without administrator rights
  • to have a better visibility on packages actually used by the application
  • to make packages and applications updates easier, as each environment can be upgraded without interfering with each other.

The only cost is the disk space used by each environment when several ones are installed concurrently.

You should note also that the *buildout* tool, actually used by all ZTFY packages (including *ztfy.webapp*), allows you to build isolated environments without the need of VirtualEnv.

Installation

VirtualEnv can be installed in several ways:

  • as a package pre-configured for your system ("apt-get install python-virtualenv")
  • from it's Mercurial repository or it's source package, as explained on project's web page (Cf link below).

Creating the environment

Creation process is the same for development phase as well as production setup.

If you installed VirtualEnv on your system, you should have a "virtualenv" command in your path.

If you are located in "/var/local/test" folder, the basic command to create the "ztfy" environment is the following one (the '--no-site-packages' option is used to disable usage of packages pre-installed on the system; it's usage can be proscribed when you need packages which are not available as eggs, but you may then encounter conflicts between several versions of the same package...):

Activating virtual environment

When virtual environment is created, you have to activate it; all Python commands will then be launched inside the virtual environment, without interfering with standard libraries installed on the system:

Installation of specific Python packages

I advise you to use the '--no-site-packages' option when you create your environments; but this can make third-party packages installed on the system unavailable from your virtual environment.

Let's take the example of python-magic, if we want to install it manually.

The first step is to install 'libmagic', to get it's sources and to build Python extension; as often, it's very easy on Debian:

As specified before, the most important point is probably to check virtual environment activation before installing package, otherwise it will be installed inside Python's system location instead of inside Python's virtual environment.