I used Django 1.3.1, Python 2.7.1, virtualenv 1.6.4 and virtualenvwrapper 2.10.1 for the scenario described in this post.
After I’d deployed my first Django site that used virtualenv, I attempted to run
sudo ./manage.py shell on the server to inspect some data on my site, but I got an error that
django.core.management couldn’t be found. I figured I hadn’t set some path properly when I saw the error, but I was a little puzzled as to which, since my site worked perfectly in the browser, but failed to run Django management commands. I opened my project’s manage.py, and noticed the interpreter directive was just pointing at the system’s
python. Since I was using virtualenv, I simply changed the Python in my manage.py to point at the one in my virtualenv and management commands worked awesomely again. See below:
Replace the first line with in manage.py with:
I’m now on OS X Lion 10.7.2 and can confirm that the steps in this post will still get Python installed on your Mac.
Why Did I Replace the Default Python on Mac OS X?
Skip to the tutorial
Mainly, because tests were failing in my Django web application on my Mac that were passing on my Ubuntu setup. So I set out to create an up-to-date Python development environment on my Mac that works the same as the one on my Ubuntu box. Having successfully put Python 2.6.6 from python.org on my Mac, and fixed my web app, I’m sharing my results, setup, and solution with community.
Other Reasons to Replace the Python That Ships with Mac OS X
Python Interpreter Output: sys.maxint and sys.maxunicode
python -c "import sys; print sys.maxint;"
- 9223372036854775807 (64-bit)
- 2147483647 (32-bit)
python -c "import sys; print sys.maxunicode"
- 1114111 (UCS-4)
- 65535 (UCS-2)
Tutorial: How I Built Python 2.6.6 (64-bit) on Mac OS X
See also: Which Version of Python Do You Already Have Installed on Mac OS X? (Opens in a new Window)
- Install XCode from the Snow Leopard DVD
- Edit the first two lines of your .bash_profile to be:
- Download Python 2.6.6 source code:
curl -O http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -xvf http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
- Edit /etc/paths and move the following line to the top of the file
./configure --disable-framework --disable-toolbox-glue \
OPT="-fast -arch x86_64 -Wall -Wstrict-prototypes -fno-common -fPIC" \
--enable-unicode=ucs4 LDFLAGS="-arch x86_64"
sudo make install
- cd into your home directory and type:
- Open an interactive interpreter session, and if I’ve been successful in my instructions, you’ll see the following with different date/time information:
Python 2.6.6 (r266:84292, Jan 30 2011, 21:45:16)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Which Version of Python Do You Already Have Installed on Mac OS X?
Open the Terminal.app and type
which python, and on a fresh install of Snow Leopard you should see:
This is a symlink that points to your actual Python installation.
cd /usr/bin; ls -l python2.6, and the output should be something like:
lrwx-xr-x 1 root wheel 75 Oct 7 23:24 python2.6 ->
Now open an interactive interpreter session:
Python 2.61 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits", or "license" for more information.
Problem: I want to see how my Django website looks
in a Parallels VM with Internet Explorer 7, 8, or some other Windows
version of a browser, but using an already-running Django
development server running on my Mac to do so.
- Shutdown your current Django development server.
- At the terminal type: ifconfig
- In the terminal output look for “en1:” > “inet”,
and copy the IP address next to inet.
- Open your settings.py or settings_local.py, and assign
the IP you copied to SITE_URL.
- Instead of the usual “runserver 127.0.0.1:8000″, replace
the 127.0.0.1 with IP you copied above (your computer’s IP).
- Use the IP address you copied in your Parallel’s VM to see the
Django site running on your development server.
Hope this helped other folks perform cross-platform IE browser-testing.
This article is
based on runserver information in the Django docs:
“Note that the default IP address, 127.0.0.1, is not accessible from
other machines on your network. To make your development server
viewable to other machines on the network, use its own IP address
(e.g. 192.168.2.1) or 0.0.0.0.”
Note: I couldn’t get the 0.0.0.0 version of this to work, but
any tips, suggestions, solutions, or otherwise are greatly appreciated.
- Mac OS 10.6.4 Snow Leopard
- Django 1.2.3
- Python 2.6.5
- Parallels 6, Windows Vista, Internet Explorer 7
Purpose: speeding up development with nose tests
Jump to section: nose step-by-step tutorial
This document describes how to setup your local development environment to run unit and/or integration tests in your Django project using nose, nose-exclude, and django-nose.
Why not just use Django’s test runner?
Recently, I worked on a heavily tested Django project. Running all tests in the project took several minutes, and the dependencies that were marked external in our Subversion project repository ran all of their tests too–each time project tests were run! I work on a team where testing frequently and committing often are tantamount to productivity. Nose tests can improve both testing speed, and subsequently accelerate development. As we walk through this tutorial you’ll begin to see how nose and its plugins (nose-exclude, django-nose) improve the productivity on any size Django project.
What nose and its plugins buy you?
- Exclude dependencies, directories, externals, or files you don’t need to test in your application.
- Run all tests that failed in the previous run.
- Identify slow-running tests.
- Get detailed information about tests that fail or error.
- Faster test runs.
- And so much more. Once you’ve completed this tutorial, open a terminal and type: nosetests –help.
What you’ll need to set up nose for Django
Although information in this tutorial can be used in almost any development environment, the walk-through for setting up nose and the related plug-ins was created and tested (of course) using the following:
Nose gotchas, tips, and other “fun”
- It seems that Synaptic Package Manager installs the older package pip-0.3.1. Don’t use it. Remove it. Do this first: Go to: System > Administration > Synaptic Package Manager > search for pip > right-click on python-pip > Mark for removal > click Apply button etc.
- Don’t use TransactionTestCase; nose wraps every test in a transaction (batteries included)
Don’t use the word “test”, or any variation thereof, in any method or class name; however, you can “exclude” certain non-tests from nose in the setup.cfg file discussed later in this tutorial.
Thanks to Jon Sackett for his comment on using the decorator @nottest on methods that have “test” in the name.
- Open a terminal, and pip uninstall or remove any previous versions of django-nose, nose, nose-exclude.
Note: This step may require finding and deleting older versions of pip installed on Ubuntu; ie. pip-0.3.1 (type pip –version to see which you have)
Next, install pip-0.6.3 if you haven’t already. Download the source tarball (pip-0.6.3.tar.gz), extract it, and cd into the extraction directory.
- In the terminal type: sudo python setup.py install
- type: pip –version (if you don’t see 0.6.3, make sure you’ve removed all pip eggs and directories system-wide, and try again.)
- terminal: pip install nose –upgrade
terminal: pip install django-nose –upgrade
- IMPORTANT: cd out of the current project you’re working in (some projects will have ‘nose-exclude’ as part of the build directory); I cd into my home directory, and then type: pip install nose-exclude.
- Now go back to your project directory, and create a new file named nose_exclude.txt. See Using File-Based Exclusion List for what should go in this file. My recommendation is to create a file named nose_exclude.txt.tmpl with some common settings to keep track of the application dependencies or directories that you don’t want or need to test.
- Likewise, create a new file in you project’s root directory named setup.cfg. This file contains the options or flags that you want to pass to “python manage.py test” every time you run tests. Optionally create one or more template files with predefined settings much like the nose_exclude.txt.tmpl file recommended above. This will help with different testing scenarios. For example, you probably don’t want to run coverage every time you execute all of your tests, but you might create a template that caters specifically to coverage or any other options not normally executed in your test runs.
- See django-nose for changes you’ll need to make to settings.py in order to run tests using nose. Depending on your development environment, you may prefer to place these edits in a different file that gets pulled into settings.py.
Finally, cd into your Django project, and type python manage.py test as you normally would. Now you have nose!
Command differences between django-nose and the Django test runner
Classes that inherit from Django’s TestCase class and their test methods require special syntax. See below for examples.
python manage.py test app.tests:YourTestCaseClass
python manage.py test app.tests:YourTestCaseClass.your_test_method
Nose usage and more examples
More nose plugins
Take a look at the plugins page for nose, or just type nosetests --help for more info. Enjoy!
Unicode Inspiration: Shapes and Symbols in Web Development by Michaux Kelley (content) is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
Based on a work at webamused.wordpress.com.
Rejoice in Unicode for Technical and Non-Technical People
If you’re not familiar with Unicode (what is unicode?),
it’s really no big deal (unless you’re a developer: why you need to know
unicode. Thank you Jeff Elmore for pointing me to this link.).
This article would addresses how to take advantage of
the symbols and shapes you can extract using Unicode. Don’t worry: few developers
have an in-depth understanding of Unicode and/or its significance, but that’s
not what this article is about so you can read on blissfully ignorant or
well-aware an not be confused or bored.
Finding Graphical Purpose Through Simplicity
In web development I frequently use arrows and other symbols to draw
attention to a particular feature on a page. Simplicity is key, because the
actual content is what’s important right? These symbols/shapes can be widely
found in most graphics programs (free and paid) with a little digging or
familiarity. However, sometimes you want a shape or symbol that stands apart
or neatly fits the bill for exactly the graphic you want display. Enter Unicode.
Unicode in Graphics as an Alternative
There are an abundance of articles dealing with how to display symbols and
shapes in an HTML web page using Unicode. Few of these suggest using graphics.
In fact, you may discover that some articles advise against using graphics
in place of text, but most of these are referring to human-readable words, not
symbols/shapes. While you could make use of Unicode textually, I advise against
it. Browser-support can be limited or spotty, styling just adds more technical
requirements to achieve what you want, Unicode-based symbols/characters will
be meaningless to vision-impaired people and don’t we type enough already?
Resources Used to For The Unicode Symbol to Graphic Conversion
My life a as a web developer has become much easier because of the
following resources (worth the download even if you don’t use them to
for the technique described in this article):
How to Make the Conversion from Unicode Symbol to Graphic
Open FireFox and Firebug: go to any Page
- Now, go to the Tools
menu. Select Firebug > Open Firebug
- From the Firebug console that opens in the bottom of the brower,
click the tab labeled HTML.
- Next, click Edit, located to the right of the bug graphic after the
Begin typing the following somewhere in the body element of
the HTML that you see: <p> & #x25BC; (remove the space between & and #)<p>. Notice that a new
symbol now appears in the page that you’re on. Keep this page open.
Right-click for Aardvark
Right-click anywhere on the page. Select Start Aardvark from the
context menu that appears.
Move the mouse over the (down-arrow) symbol that you created. An orange
border should appear. With the symbol highlighted press the i on
the keyboard. Now the symbol is all by itself.
Now press CMD/apple key (or CTRL if you’re on a PC) plus the plus symbol “+”
until you enlarge the arrow as much as possible.
Grab it with Screengrab
- Right-click on the page. Select Screengrab > Save…
- Notice that the page is highlighted in pink or some color. Click and hold
at a point to the top and left of the symbol.
- While holding the left-mouse
button down, drag in a south-east direction until the shape is surrounded
by a rectangle and release.
- In the Save As textbox of the dialog that appears rename your
shape to “DownArrow.png” (without the quotes).
- Open it with GIMPshop and begin making it the symbol you’ve always wanted.