Slide 1

Slide 1 text

Dev Environment How-To 29 Oct. 2013, Django Workshop @ CLBC

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Me •TP (@uranusjr) •http://uranusjr.logdown.com/pages/about •RTFD •Had a crash with Futura recently

Slide 4

Slide 4 text

The (Most) Comprehensive Guide to Setting up a Development Environment for Django Projects

Slide 5

Slide 5 text

The (Most) Comprehensive Guide to Setting up a Development Environment for Python Projects

Slide 6

Slide 6 text

Django A Web Framework That Does Not Require a Mac

Slide 7

Slide 7 text

Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Linux • OS X

Slide 8

Slide 8 text

Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Linux • OS X • Windows

Slide 9

Slide 9 text

Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Other things

Slide 10

Slide 10 text

Database

Slide 11

Slide 11 text

Just use PostgreSQL

Slide 12

Slide 12 text

Why? • Free as in Freedom • Recommended by dentists core developers • Data migration

Slide 13

Slide 13 text

Why? • Free as in Freedom • Recommended by core developers • Data migration

Slide 14

Slide 14 text

Matching Engines • Different engines behave differently • Fixtures are not for data migration

Slide 15

Slide 15 text

Engine Behaviour • A true story • Handling long strings • Type safety (if you use something raw) • Bugs on production machine are hard to find

Slide 16

Slide 16 text

Data Migration • Fixtures do not represent your data completely • They are just JSON, after all • You can't rollback loaddata • ContentTypes

Slide 17

Slide 17 text

SQLite Is (Still) Useful • Easy to wipe everything and start over • Quick 'n' dirty tests • Early stages during development

Slide 18

Slide 18 text

But... • MySQL is okay • Even Oracle is okay if you don't care • MariaDB • Just use it

Slide 19

Slide 19 text

Python Packages

Slide 20

Slide 20 text

What Version of Python Should I Use?

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Virtualenv • pip install virtualenv • virtualenvwrapper • pip install virtualenvwrapper • pip install virtualenvwrapper-win • pip install virtualenvwrapper-powershell

Slide 24

Slide 24 text

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?

Slide 25

Slide 25 text

virtualenvwrapper • WORKON_HOME • Load the commands (if needed) • Commands • mkvirtualenv • workon • Read the docs

Slide 26

Slide 26 text

Django and Friends • Always install packages inside virtualenv with pip • pip install django • pip install -r • pip freeze

Slide 27

Slide 27 text

This is not enough.

Slide 28

Slide 28 text

Python Has Limits • Database connector • Image processing • Other heavy-lifting tasks

Slide 29

Slide 29 text

PostgreSQL Libs (in C) • OS X • Installer or Homebrew • Linux • Your favourite package manager • Windows • Installer

Slide 30

Slide 30 text

pip install psycopg2

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

VS90COMNTOOLS ! VS100COMNTOOLS Until Python 3.2 Python 3.3

Slide 39

Slide 39 text

VS90COMNTOOLS Visual Studio 2008

Slide 40

Slide 40 text

VS100COMNTOOLS Visual Studio 2010

Slide 41

Slide 41 text

set VS90COMNTOOLS=%VS110COMNTOOLS% If you have VS2012 and Python 2.7, for example

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

I No Want C Compiler! • Pre-compiled binaries from the package manager • Pre-compiled binaries from the Web

Slide 45

Slide 45 text

Words of Warning • Version mismatch • CPU Architecture mismatch (Windows sucks) • Security issue • Why pip doesn't offer binary installing

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

Pre-Built Installer • http://www.lfd.uci.edu/~gohlke/pythonlibs/ • Simply a compressed archive (usually gzip) • Viewable with 7-Zip or similar • easy_install • Use where to make sure

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Questions?