Installing and Running Django Tutorial on Anaconda Python

So I want to do some more fluffy web based stuff with python, and, ultimately, mongodb. I’m doing things properly and starting with the Django tutorial. I’ve already installed Anaconda to provide me with a  full python 2.7 and the key data analysis packages pre-installed. The Anaconda windows installer works perfectly.

An aside, but the ipython notebook is brilliant. Runs a local webserver on your machine with the python command line running. You can record everything you do, download copies and send to others, inline graph generation, etc. It’s lovely.

Fire up a DOS command line.

So I started by checking to see if Django was already installed:

python -c "import django; print(django.get_version())"

It wasn’t. easy_install and pip often don’t work directly from the command line, with either python 2.7 installed manually  or with anaconda, so I went for the safe option that seems to work everytime and:

where python
cd C:\Users\me\AppData\Local\Continuum\Anaconda\Scripts
pip install Django

That installed Django for me fine. I checked again to see what version was installed:

python -c "import django; print(django.get_version())"

So now I need the Django Tutorial for this version. Note that if your version of Django/python is different to mine, you will need to select the right Documentation version. You can do that with the control atthe bottom RHS of the tutorial page.

Next, it wants me to create the project. I have to cd to my source folder and run a command. That command blows up:

C:\me\projects\reporting\incubator> startproject mysite
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Continuum\Anaconda\Scripts\", line 2, in <module>
from django.core import management
ImportError: No module named django.core

Sad Face. But let’s work around those pesky path issues like we did with pip:

C:\me\projects\reporting\incubator>python C:\Users\me\AppData\Local\Continuum\Anaconda\Scripts\ startproject mysite

Success. Happy Face. Mental note made. Continuing with the tutorial.

I didn’t have the sqlite3 shell installed, so downloaded it from


Finding a WinSxs Solution For Windows Server 2008

On Windows Server 2008 R2 there is no real way to manage the growth of the folder C:\windows\winsxs. This is an issue if you have virtual machines with small system partitions. Hell, it’s an issue because install files from 3 years ago are in a security protected folder that you can’t get rid of without major surgery.

There are lots of articles online from MCEs and MVPs etc saying you do DISM /this /that or COMPCLN.exe. These are all missing the point. They cleanup the stuff prior to the last Service Pack. What about the ~7 gigabytes, and growing, of OS partition space taken by this flaming folder that has no use to it all?

This technet discussion is typical.

However, I did find an article on the microsoft blog about introducing some cleanup to winsxs on Windows 7 that is non-typical, and provides a little clarity. The author, Charity Shelbourne, engages with the commenters specifically about Windows 2008. Hurrah! A comment from GerVoeten on 30th Sept, 2013 is most accurate:

The answer is the only way to clean the winsxs folder up is to uninstall updates and software. There is no guarantee that this will return back to its original size as the files maybe hard linked somewhere.
For 99.9% of us uninstalling updates and software is not really an option, these articles on cleaning up odd files in the os and using disk cleanup is a joke.

In summary, after digging around for 2 days on and off, I think there should be a canonical answer:  if you have Server 2008 R2 and you want to safely cleanup some old install files, wash your hands, pull on your rubber gloves, <small voice of reason>make some backups</small voice of reason>, you’re going in.

Please note this is specific to Windows Server 2008 R2 and doesn’t include Windows 7, Windows 2012.

Installing Python, pyMongo, and Bottle on Windows

I had no problem installing all of the above on my Mac. On Windows, however, it was a bit of a pain. Thinking about it, it maybe that the mac install was Python 2.7, which everyone has been there and done that, whereas the Windows install was python 3.3, which may be a little later to the party.

Anyway, what I did:

  1. Install python 3.3 from Use the msi installer
  2. Install the pymongo using the msi from > Look down the bottom to find the windows installers. I suggest you don’t do an easy_install, it won’t compile properly and will either not work at all, or will have degraded performance.
  3. Install distribute. The instructions are here. I found it easiest to install from cygwin/git-bash using:
     $ curl -O
    $ python
  4. Install pip using easy_install supplied by distribute. NB: you must do this from the DOS command line (and, it appears, be in the Scripts folder):
     C:\> cd c:\Python33\Scripts\
    C:\> easy_install pip
  5. I also installed bottle at this point.
     C:\> pip install bottle

Many experienced python developers are recommending using virtualenv. It allows you have a virtual python install where you can pip install anything without blowing up your base python install by accident. You may have to use the performance retarded pymongo as Windows 7 (32-bit) doesn’t have the c libraries needed to build the necessary modules.

Hat tip to khattam for the distribute/easy_install usage.

Windows Batch File Echo empty line

I rarely have to do anything windows batch files, but just sometimes I get the short straw or it’s the quick way around something.

It’s nice to be able to output something reasonably readable to the tracking file, and echoing an empty line can make things easier to parse with-my-eyes. Echo with a following special char (select your own!) does the job.

date /T
time /T
echo doing something…
echo done

echo. also works. echo? and echo either of the slashes are dubious.

Thanks to macropas on stackoverflow for that one.

Is Your Windows 32 or 64 bit?

As a developer and consultant I often need to know which version of an OS I’m on and whether it’s 32 or 64 bit. In *nix it’s trivial (uname -mrs).

But how do you find out whether Windows is 32 or 64 bit when your client’s friendly neighbourhood infrastructure and desktop team have blocked users from My Computer properties? I was surprised (again) today that systeminfo doesn’t carry this crucial information, at least, not where I could see it.

windows key + R and type dxdiag, hit return. The line Operating System tells you whether 32 or 64 bit.

TBH, I’d prefer if there was a CLI command that told me.

Need Linux With Occasional MS Office?

My father is a Linux Mint convert over the last three years, and has been running Linux Mint 9 since 2009. Unfortunately he has to use MS Office for some work things, including writing and running macros, so he can’t can’t get away from it completely (it’s for state schools usually, so it should be available in some open format, but I digress). He loathes having to select to boot windows in grub.

Anyway, recently Windows has creaked to (even more of) a crawl on his old tosh satellite, probably infected with something horrible because he rarely boots it and something got in between AVG and Spybot updates. OpenOffice on Mint 9 is getting long in the tooth. He asked me if I could think of another way around the problem that could allow him to be able to get in and out of Windows quickly, cut and paste between Windows and Linux quickly, have a better OpenOffice version and not have to worry much about the infections.

Various solutions were discussed, researched, and discarded. Some of them were:

  • Wine – MS Office is not too clever in any of the bottles yet
  • Crossover office – ditto
  • Full reinstall of Windows XP then Office 2010, then upgrade Linux Mint to 11 – going to be in same situation in x months time when XP grinds to a halt again

After a moment of clarity, we went with: upgrade to Linux Mint 11, install VirtualBox OSE, create a Windows XP VM with Office and take a snapshot, turn off networking on the VM, share a folder on the Linux box with the windows VM, and have Virus monitoring on the Linux box.

This solution gives us the fast switching between OSes; cut and paste (with the VirtualBox add-ins); the latest LibreOffice; and, when the Windows VM gets infected (pretty sure bet, even with networking turned off), rollback to the clean snapshot. Downsides are having to run an instance of Windows and MS Office. Money and sales target ticks for MS.

Here’s what we had to do. First the prep, which mostly took place before the big meetup. If we’d done all of it before, it would have saved us a couple of hours on the day.

  1. Backup /home
  2. Confirm nothing on the Windows partition needing backing up
  3. Torrent the Mint ISOs and select required version (we checked LXDE and Gnome standard. My father still prefers Gnome so we went with that)
  4. Find the Windows XP Pro install disk that came with your machine originally (you did get one, didn’t you?)
  5. Find the Windows licence code on the bottom or side of your machine
  6. Find your Office DVD and licence code
  7. Download Windows Service Pack 3

For the actual day I went a little further, just to make things more bearable:

  1. Persuade lovely wife to prepare and cook a topside of beef with all trimmings
  2. Get in sufficient wine and cheese for the day of the install

On the day, here’s the actions we went through:

  1. Confirm /home backup is ballpark. du -hs /home; du -hs /media/backupDisk/home
  2. Fire up Linux Mint 11 Live DVD and install Linux Mint 11. We have a diddy 60GB HDD so partitions were:
    • 14GB primary, mount point / – system, etc (too big, but playing for the long haul)
    • 2GB swap – logical, at end of disk
    • Rest logical (44GB-ish), mount point /home
  3. Restore /home from the backup.
  4. In Software Manager install
    • VirtualBox OSE
    • VirtualBox Add-ins ISO image
  5. In VirtualBox:
    1. create a new VM for Windows XP. Give a dynamic growth to 15GB. More than enough, but you have a lot of upgrading and installing to do and nothing is worse than a windows machine with a rammed full system disk
    2. Install Windows XP Pro (don’t even think about XP Home). Hope you have SP2 at least
    3. Install Windows Service Pack 3
    4. Install Windows Updates – there were 64 for us, the 48th was IE 8 and needed questions answering, so don’t walk away
    5. Install MS Office 2010
    6. Flag the network adapter with “cable unplugged”
    7. Start Word and fill in all the author blurb
    8. Mount a shared folder in the linux /home/username/ area (with AV protection on it). Make it permanent mount.
    9. Full screen the VM and take a snapshot
    10. Give yourself a pat on the back (and swing your pants)

    It took a long, long time, most of it getting Windows installed right, but we won’t have to do it again (I don’t think). Mint will look after itself largely, with upgrades being pretty simple now. If windows goes slow, my father can just rollback to the pristine VM image.

    Other things we wanted to do but didn’t have time:

    1. Setup sshd for remote admin access
    2. Setup LVM so we grow the disk space onto a PCMCIA card HDD at some point
    3. Setup dropbox for remote doc backups – need to investigate as last I heard dropbox had been compromised, not sure what resolution was.
    4. Setup Picasa for picture admin and remote backup
    5. Drink Bowmore