Django Dev Environment Howto

545 views

Published on

The Comprehensive Guide to Setting up a Development Environment for Django Project. Visit https://speakerdeck.com/uranusjr/django-dev-environment-howto if you like SpeakerDeck. :)

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
545
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Django Dev Environment Howto

  1. 1. Dev Environment How-To 29 Oct. 2013, Django Workshop @ CLBC
  2. 2. Me •TP (@uranusjr) • http://uranusjr.logdown.com/pages/about •RTFD •Had a crash with Futura recently
  3. 3. The (Most) Comprehensive Guide to Setting up a Development Environment for Django Projects
  4. 4. The (Most) Comprehensive Guide to Setting up a Development Environment for Python Projects
  5. 5. Django A Web Framework That Does Not Require a Mac
  6. 6. Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Linux • OS X
  7. 7. Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Linux • OS X • Windows
  8. 8. Topics • Choose your database (carefully) • Yes, when you develop • Construct a perfect Python dev machine • Other things
  9. 9. Database
  10. 10. Just use PostgreSQL
  11. 11. Why? • Free as in Freedom • Recommended by dentists core developers • Data migration
  12. 12. Why? • Free as in Freedom • Recommended by core developers • Data migration
  13. 13. Matching Engines • Different engines behave differently • Fixtures are not for data migration
  14. 14. Engine Behaviour • A true story • Handling long strings • Type safety (if you use something raw) • Bugs on production machine are hard to find
  15. 15. Data Migration • Fixtures do not represent your data completely • They are just JSON, after all • You can't rollback loaddata • ContentTypes
  16. 16. SQLite Is (Still) Useful • Easy to wipe everything and start over • Quick 'n' dirty tests • Early stages during development
  17. 17. But... • MySQL is okay • Even Oracle is okay if you don't care • MariaDB • Just use it
  18. 18. Python Packages
  19. 19. What Version of Python Should I Use?
  20. 20. 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
  21. 21. 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
  22. 22. Virtualenv • pip install virtualenv • virtualenvwrapper • pip install virtualenvwrapper • pip install virtualenvwrapper-win • pip install virtualenvwrapper-powershell
  23. 23. 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?
  24. 24. virtualenvwrapper • WORKON_HOME • Load the commands (if needed) • Commands • mkvirtualenv • workon • Read the docs
  25. 25. Django and Friends • Always install packages inside virtualenv with pip • pip install django • pip install -r <requirement_file> • pip freeze
  26. 26. This is not enough.
  27. 27. Python Has Limits • Database connector • Image processing • Other heavy-lifting tasks
  28. 28. PostgreSQL Libs (in C) • OS X • Installer or Homebrew • Linux • Your favourite package manager • Windows • Installer
  29. 29. pip install psycopg2
  30. 30. 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>
  31. 31. 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>
  32. 32. 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
  33. 33. Until Python 3.2 VS90COMNTOOLS ! VS100COMNTOOLS Python 3.3
  34. 34. VS90COMNTOOLS Visual Studio 2008
  35. 35. VS100COMNTOOLS Visual Studio 2010
  36. 36. If you have VS2012 and Python 2.7, for example set VS90COMNTOOLS=%VS110COMNTOOLS%
  37. 37. I No Want C Compiler! • Pre-compiled binaries from the package manager • Pre-compiled binaries from the Web
  38. 38. Words of Warning • Version mismatch • CPU Architecture mismatch (Windows sucks) • Security issue • Why pip doesn't offer binary installing
  39. 39. 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
  40. 40. 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
  41. 41. 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
  42. 42. Questions?

×