Wednesday, February 4, 2015

Alternate States–Python and Anaconda

While reading a great post about http://www.dataschool.io/teaching-data-science/ I came again upon the Continuum Analytics Anaconda of Python.

Once you start working with Python, some of the flaws become apparent, especially with Windows environments.  Python Package Management Sucks.  Like Linux, there are a few ways to install modules (add-ons, libraries, or packages).  PIP and easy_install are the most common outside of just using python setup.py install.  These will sometimes break if you don’t have a compiler or if they have external dependencies. It can become a bit frustrating, especially if you are just trying out some simple code and the first import fails, and you think a command line is something out of the military.

Python needs an Android-style app store…

For training and data science, Anaconda has a good distribution of Python with many of the commonly used libraries.  It uses yet another package manager, Conda.  This manager is supposed to fix some of the flaws of the other package managers by providing a better way to get some of the dependencies outside of the primary packages.

Typical syntax is to go to an Anaconda Command Prompt outside the IDE interface and run the following.

cd scripts
conda install <app>

The [Unofficial Windows Binaries for Python Extension Packages] is probably the most useful site if you’re on a Windows platform and can’t install libraries that are not compiled.

Another frustrating thing about Python which is quite similar to R is the version hell.  The latest version of Python is 3.4.  The default version of Python in many environments is 2.7.  Many libraries stick with the default version.  The simple print “hello world” command has changed between version 2.7 (2010) and 3.4 (2014).  print(“omg this is kind of batty”).

For the true immersive command-line experience on Windows, either setup a Linux box in the cloud or VM or install Cygwin tools and add the directory to your System – Advanced Settings – Environment Variables – Path.

Python does have a time travel feature which is nice, though it doesn’t seem to work well on some older versions.

http://stackoverflow.com/questions/388069/python-graceful-future-feature-future-import

from __future__ import print_function
or
import __future__, sys
if "print_function" in __future__:
# Could also check sys.version_info >= __future__. print_function.optional
import app
app.main()
else:
print "download Anaconda 3.4"

No comments:

Post a Comment