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
C:\Users\me\AppData\Local\Continuum\Anaconda\python.exe
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())"
1.6.2

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>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Continuum\Anaconda\Scripts\django-admin.py", 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\django-admin.py startproject mysite

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

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

 

Advertisements

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 http://www.python.org/download/releases/ Use the msi installer
  2. Install the pymongo using the msi from http://pypi.python.org/pypi/pymongo/ > 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 http://python-distribute.org/distribute_setup.py
    $ python distribute_setup.py
  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:

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.