Satchmo development with virtualenv

Overview

By now, most people doing Django development should be familiar with pip, virtualenv and virtualenvwrapper. If you're not, the basic problem these tools solve is how to maintain multiple versions of python libraries on your system so that you can seamlessly switch back and forth between different python environments.

For instance, when developing Satchmo, I may have 1 or 2 local branches as well as multiple forks from bitbucket. I may also have client sites in progress that are using older versions of python, django and/or satchmo. In the past, I have used some custom scripts to manage my satchmo and django versions but that process quickly got unwieldy. Coming back to a project after letting it sit for months would always be a challenge. I've also spent time tracking down problems when I realized I was pulling in the wrong version of a package that wasn't immediately obvious. Most of what I'll cover is detailed in these package's excellent docs. However, I will use a couple of the features that aren't as commonly described in other tutorials.

I am using my notes from my recent Ubuntu 10.04 upgrade. For those of you on other systems, you'll need to modify some of the apt-get code to use your system's package management tools.

Several of the python modules have libraries that are compiled from c code. I'll walk through a couple of Ubuntu libraries you can install before hand (or ensure are already installed) so that the rest of the process goes smoothly.

Dependencies

As mentioned above, I recommend you apt-get install a couple of libraries before beginning the rest of this process. These are probably already installed but if not, go ahead and do it so the rest of the process works,

Ensure you can compile c by installing build-essential:

sudo apt-get install build-essential

Now install the python development libraries:

sudo apt-get install python2.6-dev

Before installing any of the other python packages, you should install a couple of libraries so your PIL and Reportlab installs will be complete:

sudo apt-get install libjpeg62 libjpeg62-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libfreetype6 libfreetype6-dev

Python Packages

Now that those packages are installed, you can install pip, virtualenv and virtualenvwrapper:

sudo apt-get install python-setuptools
sudo apt-get install python-virtualenv
sudo easy_install pip
sudo pip install virtualenvwrapper

In order to make the most use of virtualenvwrapper, ensure the following lines are at the end of your ~.bashrc file:

export PIP_RESPECT_VIRTUALENV=true
export WORKON_HOME=$HOME/ve
source /usr/local/bin/virtualenvwrapper.sh

One quick note about the WORKON_HOME variable - that's where the virtualenvs are going to be stored. Modify that so it fits your system.

Before moving to the next step, make sure your source your new .bashrc so all the virtualenvwrapper goodness will be available to you.

Create a Virtualenv

Now, you should have all the pieces you need to create a virtualenv for Satchmo development. Let's create the isolated environment:

mkvirtualenv --no-site-packages satchmo-tip

When it's done, you should have the new environment enabled, so go ahead and install the following packages. Yes, I do know you can use a requirements file to do this in one command but for the purposes of this article, I'm showing each command:

pip install django
pip install sorl-thumbnail==3.2.5
pip install pycrypto
pip install http://www.satchmoproject.com/snapshots/trml2pdf-1.2.tar.gz
pip install django-registration
pip install reportlab
pip install pyyaml
pip install PIL

This has all been pretty straightforward virtualenv process. You should also notice that I haven't installed Satchmo or some of its dependencies yet. In my case, I am actively working on these dependencies and have full hg checkouts of all of these in /home/chris/src/hg-stuff and I would prefer to leave them there and not install a copy in this environment.

That's where the add2virtualenv command comes in handy. This command will create and add lines to a virtualenv_path_extensions.pth file in your virtualenv. I choose to link a handful of these to my development versions as shown below:

add2virtualenv /home/chris/src/hg-stuff/satchmo-working/satchmo/apps
add2virtualenv /home/chris/src/hg-stuff/django-keyedcache
add2virtualenv /home/chris/src/hg-stuff/django-threaded-multihost
add2virtualenv /home/chris/src/hg-stuff/django-caching-app-plugins
add2virtualenv /home/chris/src/hg-stuff/django-signals-ahoy
add2virtualenv /home/chris/src/hg-stuff/django-livesettings

If you don't want to do a local checkout, you could use the following commands to install them directly in your environment:

pip install -e hg+http://bitbucket.org/bkroeze/django-threaded-multihost/#egg=django-threaded-multihost
pip install -e hg+http://bitbucket.org/bkroeze/django-caching-app-plugins/#egg=django-caching-app-plugins
pip install -e hg+http://bitbucket.org/bkroeze/django-signals-ahoy/#egg=django-signals-ahoy
pip install -e hg+http://bitbucket.org/bkroeze/django-keyedcache/#egg=django-keyedcache
pip install -e hg+http://bitbucket.org/bkroeze/django-livesettings/#egg=django-livesettings
pip install -e hg+http://bitbucket.org/chris1610/satchmo/#egg=satchmo

Putting it all together

Assuming it's all working for you, you should be able to use the workon command to see your environments:

[email protected]:~$ workon
satchmo-0.9
junk
satchmo-tip
django1-1

Now, workon on your new satchmo environment:

 [email protected]:~$ workon satchmo-tip
(satchmo-tip)[email protected]:~$

If you want to see your site packages, try this:

cdsitepackages
lssitepackages

I find those two commands very useful for seeing what is installed in your environment.

Now that your environment is setup, you can build your satchmo store in an isolated location that is totally independent from any other python and django projects on your system. I find this is a great way to experiment with multiple projects and decide which ones may or may not warrant additional study.

EDIT: Nov 28, 2010: Added specific version to sorl thumbnail install.

Posted on August 1, 2010 by chris django satchmo

19 Comments

Sergej commented on August 2, 2010 at 11:51 a.m.:
Thank you!

Reply
Rob Ottawway commented on August 13, 2010 at 10:25 a.m.:
Very helpful post, I've been handling virtualenv tasks with custom scripts, wrapper is a godsend!

Reply
Mat commented on August 30, 2010 at 4:56 a.m.:
Thanks for sharing those useful tips.

Reply
software development commented on September 29, 2010 at 2:18 a.m.:
Nice, thanks for the training. I've used VirtualEnv from another tutorial, but it didn't really explain what it did, how it related to django developers, and why I needed it. I ended up not needing it. It was hard to setup though.

Reply
internet marketing melbourne commented on October 4, 2010 at 6:07 a.m.:
I assume you're just letting us know what you have done and aren't asking a question :) If that's the case, two things I'd add to this: There seems to be some suggestion that on Ubuntu you should use the python-virtualenv package: http://groups.google.com/group/python-virtualenv/browse_thread/thread... sudo apt-get install python-virtualenv Also, to get PIL to compile with jpeg and png support, I had to install: sudo apt-get install libjpeg62-dev sudo apt-get install libjpeg62 sudo apt-get install zlib1g-dev Finally, I highly recommend installing virtualenvwrapper to make managing the ve's much easier: sudo pip install virtualenvwrapper Once you install that you can type: workon and see all your VE's and workon ve-name to activate it. Thanks for the writeup.

Reply
sorin commented on October 5, 2010 at 2:38 p.m.:

One small update: replace .bashrc with .profile and it will work for all users. .bashrc doesn't work for www-data user on the same ubuntu distro like yours ;)



Reply
sorin commented on October 5, 2010 at 2:48 p.m.:

2nd: add apt-get install libyaml-dev



Reply
Toronto Marketing Company commented on October 9, 2010 at 4:07 a.m.:
It is very valuable post and nice comment if you want to some more information about internet marketing and web development then "Toronto Marketing Company" can help you.

Reply
James commented on October 13, 2010 at 10:25 a.m.:
This is a great post and really helped me as a Python newbie. I just have a couple of questions you might be able help me with: 1. Now I have created an environment for building satchmo stores, is it possible to move that environment to another machine (another mac) providing its machine specific binaries are present for RepotLab, Freetype etc? 2. Can I use this environment in production? 3. Can I upgrade to the latest versions of the hg checkouts using PIP? Having all the required dependancies in one place is great I really hope its portable too!

Reply
Matt Snow commented on November 17, 2010 at 7:22 p.m.:
And I have one question: What IDEs are best suited for Django development?

Reply
Printer Support commented on December 28, 2010 at 1:29 a.m.:
Hi, I am using my notes from my recent Ubuntu 10.04 upgrade. For those of you on other systems, you'll need to modify some of the apt-get code to use your system's package management tools.

Reply
plus size dresses commented on January 13, 2011 at 4:45 a.m.:
I like your site, I will show my friends about your network, and I wish you to change into greater and come to new subjects

Reply
loco commented on January 13, 2011 at 4:45 a.m.:
Your online page is always accessible to your clients in opposite to <a href="http://www.plussizetrendyclothing.net/c-46-cheap-plus-size-dresses.aspx">plus size dresses</a> shop, which are out of service at Weekends

Reply
Majid commented on February 2, 2011 at 3:29 a.m.:
Is this project still active or not ? I can see that the latest post for the website is for 6 months ago. Is it still active in development ?

Reply
carver commented on February 17, 2011 at 1:18 a.m.:
@Majid - a quick look at bitbucket shows that the latest commit was yesterday, so there does seem to still be active development.

Reply
me commented on September 9, 2011 at 9:40 a.m.:

$clonesatchmo.py -s test
Creating the Satchmo Application
Customizing the files
Performing initial data synching
Unknown command: ‘satchmo_copy_static’
Type ‘manage.py help’ for usage.
Traceback (most recent call last):
File “manage.py”, line 27, in
execute_manager(settings)
File ”$HOME/ve/satchmo-tip/lib/python2.7/site-packages/django/core/management/init.py”, line 438, in execute_manager
utility.execute()
...
File ”$HOME/ve/satchmo-tip/lib/python2.7/site-packages/django/conf/init.py”, line 89, in init
raise ImportError(“Could not import settings ’%s’ (Is it on sys.path?): %s” % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings ‘test.settings’ (Is it on sys.path?): No module named settings
Store setup had the following setup errors:
– Can not copy the static files.
– Can not syncdb.



Reply
me commented on September 9, 2011 at 9:43 a.m.:
Meant to say, it doesn't work for me on 11.04 using the system pip and virtualenvwrapper (otherwise following all the other steps). The Satchmo installation guide seems to assume that closesatchmo.py will just work, so not sure how to proceed.

Reply
Chris commented on December 24, 2011 at 10:09 a.m.:
In newer versions of Ubuntu, you may have to follow the suggestions here - http://stackoverflow.com/questions/7648200/pip-install-pil-e-tickets-1-no-jpeg-png-support

Reply
jason commented on August 28, 2012 at 9:07 a.m.:
you can also do pip install yolk then use yolk -l to list your currently installed packages within your virtualenv.

Reply

Reply to original: