6

I will be installing and maintaining a Python 2.7-based server application on Ubuntu server (12.04). The model of maintenance will be to create a virtualenv and install application standard libraries (from PyPI) and custom libraries (bespoke) there, updating them as required. A separate folder holds the "application", which is made up of configuration files and application-specific Python files.

As far as I can tell, the only Ubuntu-provided packages I require are python and python-virtualenv. I may do a custom installation of pew to manage the venv - in which case I will sudo easy_install pew and accept that wherever it goes is correct (pew isn't in the 12.04 repo).

I have a vague awareness that applications should live in /opt or /srv or somewhere like that, and that a server application may live in a different location to a user application. Give all that:

  • where should the virtualenv be located?
  • where should the server application folder be located?
2

Essentially the location of the virtualenv is irrelevant. You can place it wherever you want. You just have to run source some_venv/bin/activate and then you're set to go.

The traditional location is ~/.virtualenvs.

I use a different setup where I have a ~/projects folder which contains the different virtualenvs and contains the python code for different projects. This is nice and easy because you have everything together. For some it might look a bit cluttered, because you get a bin, local, and more folders in your venv.

I manage these using virtualenvwrapper which is in the repos. I did not get the chance to test pew, yet.

If virtualenvwrapper and virtualenv are set up correctly, the workflow is:

mkvirtualenv some_venv
workon some_venv
cdvirtualenv
deactivate
1

For Django applications, Adam Bard recommends locating your virtualenv at /opt/apps/<appname>-env and your application proper at /opt/apps/<appname>-env/site. (Many thanks to don.joey for the excellent link.)

Slightly unrelated, I also found Hynek Schlawack's Python Deployment Anti-Patterns and Python Application Deployment with Native Packages to be useful reads.

Based on this, my own review of the Filesystem Hierarchy Standard and an inspection of the /opt folder on my desktop machine, I went with:

  • /opt/virtualenv/<env_name> for the virtual environment
  • /opt/<vendor_name>/<app_name> for the server application folder

This allows me to create multiple independent virtualenvs and application folders for different applications, versions, etc as I see fit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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