I’m setting this up for my own python development, and so far it’s working LIKE A BOSS. Using my workstation as a development environment, and a server as the production environment, I’m synergizing the deliverables by maximizing throughput in the signal/noise ratio.
Erm.
That is, I’m using virtualenv (and a set of popular virtualenv wrapper scripts) along with git to keep development and deployment of python projects with varying dependencies in sync.
It’s disturbingly easy to set up:
- Install virtualenv
- Install virtualenvwrapper
- Put the virtualenvwrapper directory in version control
- create a virtualenv for each project
It’s that easy!!!
I’m a fan of using pip to install everything. It’s the future of python package management because it’s so flippin’ easy to use, as well as being sanely implemented. The copypasta for the above setup runs something like this:
pip install virtualenv pip install virtualenvwrapper mkdir ~/.virtualenvs
Add the following to your .bashrc:
export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper_bashrc
then:
source ~/.bashrc mkvirtualenv projectname cd ~/.virtualenvs git init
Now feel free to start using pip to build up the particular python environment the project will need, commiting the ~/.virtualenv directory to git as needed. When you’ve got your python libraries how you like, install virtualenv on the production server, and add it to the repository for your project. I’m thinking I’ll set it as a git submodule for Django projects, but so far I’ve just been keeping it as a separate repository for non-public in-development non-website projects.
I am curious why you are keeping the virtualenv in version control. With pip you can use a requirements file in your project which will manage all of that for you so you aren’t copying binaries, egg files, etc.
Using your example above:
$ mkdir projectname
$ cd $_
$ git init
$ $EDITOR requirements.txt
#— requirements.txt
Pygments
-e svn+http://code.djangoproject.com/svn/django/trunk/#egg=Django
#—
$ git commit -a -m “Init requirements file for projectname”
$ pip -E projectname -r requirements.txt
That last pip command creates a virtualenv with the libraries you needed installed via the requirements file. Makes it really easy to just manage your project and let pip do the heavy lifting.
Got here from planet.emacsen.org and will be following the blog. Good luck!
Curt,
The reason I’m doing it this way is that I only recently started looking into pip, and haven’t delved into the requirements files yet.
$ pip -E projectname -r requirements.txt
Now I need to question my reading comprehension skills, since I did not realize that one can create a virtualenv from within pip. Superlatives fail me.
Patrick,
It gets even fancier, read up on pybundles. (Using the requirements file above):
pip bundle projectname.bundle -r requirements.txt
This zips up all the libraries, you can then move the bundle around without needing to download and install the libraries.
pip is super sexy.
shouldn’t
$ pip -E projectname -r requirements.txt
be
$ pip install -E projectname -r requirements.txt