Getting Started With Python

Introduction

I thought it would be useful to learn at least some Python, since Django is a popular web framework.

It is a bit more complicated than I would like to set up Python on my Mac, so I thought I would document what I needed to do to get it working.

Python Versions

The first confusing thing about Python is that there are currently two different versions of the language. How different are they? I don't really know.

Maybe I could just learn Python 2 and it wouldn't be a big deal to switch to Python 3 later, but this doesn't seem to be the generally accepted advice in the community.

It seems that Python 3 is the future, the thing that new Pythoners should be learning and the recommended language for Django.

So, Python 3 it is.

Mac Python

Macs come with Python already installed, but guess what? It's version 2. Also, you can't just upgrade it, because some things in MacOS rely on Python 2 being there (??)

You can install Python 3 alongside Python 2 in different ways (installer, Homebrew) but then you're going to have to deal with different dependencies.

When I installed Python 3.6 using the package installer for Mac and then launched 'IDLE' from it's directory (in /Applications/Python3.6) I got a warning about the version of tk/tcl that I'm running. There was a URL giving more information - it seems that the people who maintain Python are not happy with Apple and I should install a different version of this software that I've only vaguely heard of.

Basically, I feel like I could be entering a world of pain by messing with my settings. It would be much better to just get a complete environment to learn in, with everything I need sandboxed away from the rest of the system. Can I do that?

It seems like I can - virtualenv would appear to be the thing I'm looking for, possibly with virtualenvwrapper and possibly I can get everything using virtualenv-burrito (https://github.com/brainsik/virtualenv-burrito).

Does this virtualenv let me fix the problem with tk/tcl without having to update system software?

Django has some instructions for setting up virtualenv: https://docs.djangoproject.com/en/1.11/intro/contributing/

A Working Environment

How can I test my Python environment?

Django

I confess, I don't really have a need in my life to write Python. I don't really need to write Python except that I want to learn how Django works.

So, I'd better make sure that I'm going to be able to install Django and actually deploy what I make. If I can't deploy it somewhere, it's pretty useless to me.

Heroku

The obvious place to deploy a 'toy' app into 'production' is Heroku. They seem to have good documentation for deploying Django apps, but they also (strongly) recommend a particular template.

Using their template might complicate things a bit - there will be stuff in there doing things that I don't understand yet, but it will also ensure I'll be able to deploy what I make.

The Heroku Django Template is here: https://github.com/heroku/heroku-django-template

Set Up a Project and Test Deployment

Making sure I can deploy whatever I make is very important (the only reason I'm doing this at all is to show to other people) so I really want to make sure I'm able to deploy my app. For that reason then, I like to go through these hoops before I even start learning anything.

Databases

Django knows about databases. We should set one up.

I would like to learn about Postgres as well, so I will use that. This is likely to add more complication to the Heroku set up (but there's also a chance it's already factored in to the template).

Installing Django Notes: https://docs.djangoproject.com/en/1.11/topics/install/#installing-official-release

What Next?

Next comes some combination of learning Django (https://www.djangoproject.com/start/), Learning Python