Wednesday, December 5, 2012

Where to get Python?

In the Udacity CS101 forum, a frequent question from students has been where to get Python for their own computer. For example, see http://forums.udacity.com/questions/2006201/the-compiler#cs101

Here is my reply to that question:

It's called an interpreter in Python's case, not a compiler. A true compiler translates source code to executable machine code. More dynamic languages, e.g. Python, Perl and Java, translate the source code into a more compact form and then have an interpreter that runs the program for you. The exact meanings of even "simple" stuff like the + operator depends on the types of the operands and the types in Python might not be known until runtime. The traditional thinking is that an interpreted language (e.g. Python) is doomed to have worse performance than a compiled language (e.g. C), but it turns out that's a lot more interesting an argument than it was just a few years ago. If you want to take a deep dive into a technical computer science discussion of this matter, I suggest you spend some time watching Dynamic Languages Strike Back. It's a very technical talk, and I, for one, had to look up quite a few things mentioned in the talk. Don't let that throw you. Take notes while you view the video and, later, Google up more info on the topics you hear mentioned but didn't really know. If you are interested in computer science, I assure you its a worthwhile talk.

Getting to your question: The version of Python used in udacity's CS101 is Python 2.6.6. The most current version of 2.6 at this time is 2.6.8. There are multiple versions available and the details of how to install it depend on your choice of operating system. If you run Linux or a Mac, it is very likely that there's already a Python interpreter on your computer. If you are running Windows, there are choices to make. The cygwin package from cygwin.com provides Unix-like commands on Windows and optionally can install a nice Python environment on your Windows PC. But be forwarned that if you want to write software that is closely wedded to Windows, cygwin may not be the right choice. There are still more choices and most all of them are free. Google for

python windows

and it'll find lots of pages for you. There's a packaging called Portable Python that comes with lots of extra modules bundled in. You can install it on a USB flash-drive and run from there without having to really install anything on whatever Windows PC you walk up to. Just plug in your USB drive and "wherever you go, there you are". I mostly run Ubuntu Linux here, so I have little experience with Native Windows Python. So, I don't really know how hard it is to incorporate another module into the Portable Python environment. I did install Python and wxpython and the Eric IDE on my wife's Windows PC. Compared to the ease of pulling in optional packages on Ubuntu, Windows doesn't make it easy to pull your python environment together. Keep good notes of exactly what you install and where you got it from and what the steps were to install the pieces. Unless you have a specific piece in mind that doesn't come with Portable Python, I think I'd pick Portable Python if Cygwin isn't suitable for you.

Not entirely free, but with much more formal support available, there's a company called ActiveState that markets a rich bundle of Python and Python modules all integrated together and with commercial support. Probably not the right choice for an individual student or hobbyist, but if you wanted Python for Windows for a commercial application, ActiveState is certainly a company you'd want to talk to. Or, if you want to write for the Microsoft .NET environment, then by all means talk to Microsoft about Iron Python. Bring money if that's what you want, because it isn't free.

Another alternative to consider is Python in the Cloud. PythonAnywhere is built atop Amazon's cloud computing service. For small stuff, accounts are free. It's a reasonably rich "batteries included" environment. It has the advantage of nothing for you to install at your end, and the promise that if your application becomes a Farmville-like success, that the infrastructure can handle your needs (but at some point in your huge success, you will have crossed the line from "free" to you-need-to-pay-for-your-account). Google Apps is another way to do Python in the Cloud. I've barely dabbled in that...

And you probably thought you were asking a simple question. My apologies if my answer has muddied the water. If you want a simple answer for Windows, look at cygwin and at Portable Python. This may be a good time to wave bye-bye to Mr. Gates and move to Linux instead of Windows.

Does that help?

Addendum

Since writing the above, I was pleasantly surprised to learn from other postings to the Udacity forum how many Python-in-the-cloud interpreters there are, at least for small development use. The list at http://forums.udacity.com/questions/2000116/online-interpreters#cs101 may be helpful.

The visual debugging at http://www.pythontutor.com/visualize.html# is particularly special, at least if you are dealing with small amounts of code. For larger scale programs, particularly programs that import other modules, I stand by my suggestion of PythonAnywhere or GoogleApps.