Dev Environment
How-To
29 Oct. 2013, Django Workshop @ CLBC
Me
•TP (@uranusjr)
• http://uranusjr.logdown.com/pages/about

•RTFD
•Had a crash with Futura recently
The (Most) Comprehensive
Guide to Setting up a
Development Environment
for Django Projects
The (Most) Comprehensive
Guide to Setting up a
Development Environment
for Python Projects
Django
A Web Framework That Does Not Require a Mac
Topics
• Choose your database (carefully)	

• Yes, when you develop	

• Construct a perfect Python dev machine	

• Linux	

• OS X
Topics
• Choose your database (carefully)	

• Yes, when you develop	

• Construct a perfect Python dev machine	

• Linux	

• OS X	

• Windows
Topics
• Choose your database (carefully)	

• Yes, when you develop	

• Construct a perfect Python dev machine	

• Other things
Database
Just use PostgreSQL
Why?
• Free as in Freedom	

• Recommended by dentists core developers	

• Data migration
Why?
• Free as in Freedom	

• Recommended by core developers	

• Data migration
Matching Engines

• Different engines behave differently	

• Fixtures are not for data migration
Engine Behaviour
• A true story	

• Handling long strings	

• Type safety (if you use something raw)	

• Bugs on production machine are hard to find
Data Migration
• Fixtures do not represent your data completely	

• They are just JSON, after all	

• You can't rollback loaddata	

• ContentTypes
SQLite Is (Still) Useful
• Easy to wipe everything and start over	

• Quick 'n' dirty tests	

• Early stages during development
But...
• MySQL is okay	

• Even Oracle is okay if you don't care	

• MariaDB	

• Just use it
Python Packages
What Version of
Python Should I Use?
Python
• Anything over 2.7.0 should be enough	

• YUM is still based on 2.6... Oops.	

• Python 3 is coming…or not	

• Having both Python 2 and 3 installed on Windows
can be a nightmare
Setuptools and PIP
• https://bitbucket.org/pypa/setuptools/raw/
bootstrap/ez_setup.py	

• python ez_setup.py	

• Modify PATH environment variable if needed	

• easy_install pip
Virtualenv
• pip install virtualenv	

• virtualenvwrapper	

• pip install virtualenvwrapper	

• pip install virtualenvwrapper-win	

• pip install virtualenvwrapper-powershell
WUT?
• setuptools = Python's package manager	

• Ever heard of distribute?	

• pip = Better easy_install alternative	

• virtualenv = Prevent Python lib pollution	

• virtualenvwrapper = Better virtualenv UI	

• Windows variants	

• Didi I hear somebody say APT?
virtualenvwrapper
• WORKON_HOME	

• Load the commands (if needed)	

• Commands	

• mkvirtualenv	

• workon	

• Read the docs
Django and Friends
• Always install packages inside virtualenv with pip	

• pip install django	

• pip install -r <requirement_file>	

• pip freeze
This is not enough.
Python Has Limits
• Database connector	

• Image processing	

• Other heavy-lifting tasks
PostgreSQL Libs (in C)
• OS X	

• Installer or Homebrew	

• Linux	

• Your favourite package manager	

• Windows	

• Installer
pip install psycopg2
Build a C Extension
• Get a C compiler	

• Install (or compile) library to bind with	

• Install CPython headers	

• apt-get install python-dev	

• pip install <binding_package>
Build a C Extension
• Get THE ONE TRUE C compiler	

• Install (or compile) library to bind with	

• Install CPython headers	

• apt-get install python-dev	

• pip install <binding_package>
Get a Compiler
• apt-get install build-essential	

• OK, I got lazy :p	

• Install Xcode and its "console tools"	

• Install Visual Studio (Express)	

• The "for Windows Desktop" version	

• Use the correct prompt
Until Python 3.2

VS90COMNTOOLS	

!

VS100COMNTOOLS
Python 3.3
VS90COMNTOOLS
Visual Studio 2008
VS100COMNTOOLS
Visual Studio 2010
If you have VS2012 and Python 2.7, for example
set VS90COMNTOOLS=%VS110COMNTOOLS%
I No Want C Compiler!

• Pre-compiled binaries from the package manager	

• Pre-compiled binaries from the Web
Words of Warning
• Version mismatch	

• CPU Architecture mismatch (Windows sucks)	

• Security issue	

• Why pip doesn't offer binary installing
From APT
• apt-get install python-psycopg2	

• What does it install?	

• http://packages.debian.org	

• .deb file is merely an ar archive	

• ln -s everything into $ENV/lib/site-packages
Pre-Built Installer
• http://www.lfd.uci.edu/~gohlke/pythonlibs/	

• Simply a compressed archive (usually gzip)	

• Viewable with 7-Zip or similar	

• easy_install <installer_path>	

• Use where to make sure
Miscellaneous
• http://rudix.org has pre-built packages for OS X	

• I never used it, to be honest :p	

• RPM packages can be converted with rpm2cpio and
then extracted with cpio	

• Actually you can use MinGW	

• Why?	

• If you really know what you're doing
Questions?

Django Dev Environment Howto