Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django Dev Environment Howto

Django Dev Environment Howto

The Comprehensive Guide to Setting up a Development Environment for Django Project. SlideShare entry here: http://www.slideshare.net/uranusjr/django-dev-envhowto

9dafad54b5b4f360b7aae5f482bc1c91?s=128

Tzu-ping Chung

November 06, 2013
Tweet

More Decks by Tzu-ping Chung

Other Decks in Programming

Transcript

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

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

    recently
  4. The (Most) Comprehensive Guide to Setting up a Development Environment

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

    for Python Projects
  6. Django A Web Framework That Does Not Require a Mac

  7. Topics • Choose your database (carefully) • Yes, when you

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

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

    develop • Construct a perfect Python dev machine • Other things
  10. Database

  11. Just use PostgreSQL

  12. Why? • Free as in Freedom • Recommended by dentists

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

    developers • Data migration
  14. Matching Engines • Different engines behave differently • Fixtures are

    not for data migration
  15. Engine Behaviour • A true story • Handling long strings

    • Type safety (if you use something raw) • Bugs on production machine are hard to find
  16. Data Migration • Fixtures do not represent your data completely

    • They are just JSON, after all • You can't rollback loaddata • ContentTypes
  17. SQLite Is (Still) Useful • Easy to wipe everything and

    start over • Quick 'n' dirty tests • Early stages during development
  18. But... • MySQL is okay • Even Oracle is okay

    if you don't care • MariaDB • Just use it
  19. Python Packages

  20. What Version of Python Should I Use?

  21. 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
  22. 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
  23. Virtualenv • pip install virtualenv • virtualenvwrapper • pip install

    virtualenvwrapper • pip install virtualenvwrapper-win • pip install virtualenvwrapper-powershell
  24. 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?
  25. virtualenvwrapper • WORKON_HOME • Load the commands (if needed) •

    Commands • mkvirtualenv • workon • Read the docs
  26. Django and Friends • Always install packages inside virtualenv with

    pip • pip install django • pip install -r <requirement_file> • pip freeze
  27. This is not enough.

  28. Python Has Limits • Database connector • Image processing •

    Other heavy-lifting tasks
  29. PostgreSQL Libs (in C) • OS X • Installer or

    Homebrew • Linux • Your favourite package manager • Windows • Installer
  30. pip install psycopg2

  31. None
  32. None
  33. None
  34. 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>
  35. 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>
  36. 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
  37. None
  38. VS90COMNTOOLS ! VS100COMNTOOLS Until Python 3.2 Python 3.3

  39. VS90COMNTOOLS Visual Studio 2008

  40. VS100COMNTOOLS Visual Studio 2010

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

    example
  42. None
  43. None
  44. I No Want C Compiler! • Pre-compiled binaries from the

    package manager • Pre-compiled binaries from the Web
  45. Words of Warning • Version mismatch • CPU Architecture mismatch

    (Windows sucks) • Security issue • Why pip doesn't offer binary installing
  46. 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
  47. 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
  48. 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
  49. Questions?