Installing Satchmo
Intro
Satchmo is an ecommerce application based on the Django web application framework. You would use Satchmo to build an on-line shop, for example. You might choose Satchmo as an alternative to, say, osCommerce. The difference between osCommerce and Satchmo is the difference between php and python.
Installing Satchmo, I followed the Satchmo installation guide on the Documentation wiki and ran into quite a few difficulties. Some, but not all, of these were resolved by searching or posting to Satchmo users.
I have now successfully completed "installation" and am ready to embark on "configuration". These notes summarise the story so far.
n.b. These notes run Django & Satchmo on a Django test server (i.e., python manage.py runserver). I’ll cover running on a real web server in a later article.
Prerequisites
System requirements are listed here. Essentially it’s Python 2.4 or later, a recent Django release (they have a known working snapshot), and a few other packages. Apart the Django requirements, I installed everything with apt-get with no problems (I’m running Debian testing).
Installing and setting up Django was very easy, and in fact fun. Their documentation is really excellent, with an installation guide and a four part tutorial.
Note that django-comment-utils and Django Registration are not optional.
Note also that PyYaml is required to load the initial data.
Install Satchmo
Unpack the tarball, cd to the satchmo-0.6.0 directory and type:
python setup.py install
You may need superuser privileges.
Setting up Satchmo and Django
For the following I’ll assume we’re setting up Satchmo as part of a Django project. In fact, I’ll assume we’ve just done the Django tutorial and you have a directory structure like this:
mysite/ __init__.py manage.py settings.py urls.py polls/ mytemplates/ 404.html 500.html admin/ polls/
The Django tutorial explains what all this means (and if you don’t know what it means you should probably do the tutorial before proceeding).
We’ve installed Satchmo python code onto our computer, now we need to install Satchmo into the Django project. This involves two steps (so far - more to follow in "configuration"):
- settings: altering settings.py to include settings for Satchmo;
- shop: setting up the demo shop application.
The relevant page on the Satchmo documentation wiki is SatchmoInstallation.
settings
To the basic settings.py created in the Django tutorial, Satchmo adds settings in two files (satchmo/settings-customize.py and satchmo/local_settings-customize.py). SatchmoInstallation recommends you to:
- copy local_settings-customize.py to mysite/local_settings.py;
- edit this local_settings.py file for your setup (e.g. DJANGO_SETTINGS_MODULE, etc.)
- Append the following line to the end of your settings.py: from local_settings import *
If you follow these instructions carefully you will break your Django project. For example, local_settings.py contains the line:
TEMPLATE_CONTEXT_PROCESSORS += ('satchmo.shop.context_processors.settings',)
As TEMPLATE_CONTEXT_PROCESSORS is not defined before being incremented, this causes a NameError which crashes the server.
This file - settings_satchmo.py - brings the Satchmo settings together into one place. The easiest and safest thing is to paste the whole lot into the end of yoursettings.py file. This file - settings_django.py - is more-or-less the settings.py from the Django tutorial. I have verified that Django and Satchmo works when the two are amalgamated into one settings file (e.g., cat settings_django.py settings_satchmo.py > settings.py).
Obviously, this cutting and pasting is a horrible kludge and a more general solution is required: loading settings for individual Django apps into a central settings module. However, at least it works and it’s simple enough for the moment.
shop
Step 9 of SatchmoInstallation begins:
Copy (for windows) or symlink satchmo/tax/ and satchmo/load_data.py into the root of your app.
Load the sample data:
python load_data.py
I have found that (on linux) symlinking load_data.py does not work, as Python tries to find settings.py in the working directory of the real file, whereas we want it to look for settings.py in the working directory of the symlink. Therefore we need to copy load_data.py into mysite/. satchmo/tax/ can be symlinked.
For a reason I haven’t been able to work out, load_data.py does not work (for me) from the command-line. i.e.:
$:~/mysite$ python load_data.py
Type 'yes' to erase ALL data and reinstall ALL models: no
Type 'yes' to erase any existing Satchmo data and reinstall all models: yes
Deleting existing Satchmo data.
Traceback (most recent call last):
File "load_data.py", line 346, in ?
eraseDB(all=False)
File "load_data.py", line 317, in eraseDB
delete_satchmo()
File "load_data.py", line 57, in delete_satchmo
app = models.get_app(app_name.split('.')[-1], emptyOK=True)
File "/usr/lib/python2.4/site-packages/django/db/models/loading.py", line 118, in get_app
mod = self.load_app(app_name, False)
File "/usr/lib/python2.4/site-packages/django/db/models/loading.py", line 74, in load_app
mod = __import__(app_name, {}, {}, ['models'])
File "/usr/lib/python2.4/site-packages/satchmo/shop/models.py", line 13, in ?
from satchmo.contact.models import Contact
File "/usr/lib/python2.4/site-packages/satchmo/contact/models.py", line 17, in ?
import config
File "/usr/lib/python2.4/site-packages/satchmo/contact/config.py", line 9, in ?
description=_("Account Verification"),
File "/usr/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 61, in ugettext
return real_ugettext(message)
File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 274, in ugettext
return do_translate(message, 'ugettext')
File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 261, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 184, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 167, in _fetch
app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
ImportError: No module named mysite
But load_data.py works perfectly well from the Django shell. So, assuming you want to keep Django settings, but initialise and install all the Satchmo data, do this:
$:~/django_satchmo_etc/mysite$ python manage.py shell Python 2.4.4 (#2, Jan 3 2008, 13:36:28) [GCC 4.2.3 20071123 (prerelease) (Debian 4.2.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from load_data import * >>> >>> ## eraseDB(False) deletes any Satchmo data, ... >>> ## ... and installs localisation data >>> ## n.b. eraseDB(True) deletes your entire Django installation! >>> eraseDB(False) ## same as eraseDB() Deleting existing Satchmo data. Deleting satchmo.shop Deleting satchmo.supplier Deleting satchmo.payment Deleting satchmo.discount Deleting satchmo.contact Deleting satchmo.product Deleting satchmo.tax Deleting satchmo.l10n Satchmo data successfully deleted. Calling syncdb Loading 'initial_data' fixtures... No fixtures found. Loading 'l10n_data' fixtures... Installing xml fixture 'l10n_data' from '/usr/lib/python2.4/site-packages/satchmo/l10n/fixtures'. Installed 5155 object(s) from 1 fixture(s) >>> >>> ## load_data() loads up the demo shop >>> load_data() Creating site... Creating Customers... Creating Suppliers... Creating Categories... Creating products... Creating product variations... Create a test user... >>> >>> ## this loads up US tax data >>> load_US_tax_table() >>>
Now if we run the test server (python manage.py runserver) the demo shop should be at localhost:8000/shop. Everything should be working.
Conclusion & further work
The poor documentation and the apparent idiosyncracies of settings-*.py and load_data.py were annoying, but now the site is working all is forgiven. I’m ready to go ahead with configuration. Watch this space!
March 22nd, 2008 at 3:14 pm
Thanks for the notes and thanks for sticking with it. I’ll try to use your ideas and comments to make things a little easier for everyone else in the future!
March 22nd, 2008 at 11:14 pm
[…] dairy diary « Installing Satchmo Satchmo […]