- I am using the Enthought Canopy python distribution and IDE on all my machines now (MacBook Pro, 2 Dell Alienware PC's, and fjord-linux), using a single, free academic license.
- Get it from here. I got the Full installation because the Express installation lacked key packages. You navigate to the Academic page, and then log in with your license. Then download a file like canopy-1.5.1-full-rh5-64.sh. You get a different one for different systems (linux, mac, pc; I think I always got the 64 bit version. Note that to get the Full one you have to use the button in the middle of the page with the text: "Need to download the complete package installer at once for shared installation or offline computers?" One symptom of not having the Full version is that import netCDF4 fails, and hence make_forcing_main.sh ocn fails.
- On fjord I just put it in /home/parker = ~, and followed the directions here. This involved just a few steps, all from the linux command line (assuming you are in ~):
- bash canopy-1.5.1-full-rh5-64.sh (This creates things like the Canopy folder)
- ~/Canopy/canopy (This sets up the environment. You have to be logged in using ssh -X, because it brings up a GUI window along the way. Accept all defaults.)
- To run from the command line on fjord, e.g. using "ipython --pylab" (aliased to ipy), you have to logon to fjord with X-windows enabled ("ssh -X ...", aliased to fjx on my mac).
- You can also bring up the full X-window IDE by typing canopy (in ~).
- The installation for the mac version is different, using a mere standard disk image that you drag into /Applications.
- In the end on fjord "which python" returns ~/Enthought/Canopy_64bit/User/bin/python, and on my mac it returns /Users/PM3/Library/Enthought/Canopy_64bit/User/bin/python.
- To update libraries on the mac you just use the package manager. The easiest way to do this on fjord is to also go through the canopy IDE.
To add libraries outside of Canopy, here is an example:
- I needed the Windows Azure Python SDK...
- Find it by searching for Azure at pypi.python.org
- download azure-0.9.0 = (*) or whatever is the latest, and put it in /Applications on my mac or /home/parker on fjord.
- then from the command line (mac or fjord) go to the folder (*) and execute: python setup.py install
- then in python "import azure" works (check it!).
- As of November 2014 the azure module was not working on fjord (it worked fine on my mac, though). The fix was to use the Anaconda python installation instead.
Notes on the editor in Canopy:
- To tab a block of text, select it and press TAB. Use SHIFT+TAB to un-indent a block
- To comment or uncomment a block CMD+/
- # for comments
- Command line notes:
- command line comes up automatically in the Canopy IDE or using "ipython --pylab" (aliased to ipy) from the terminal command line
- run test will run the code test.py, or just push the green arrow at the top of the IDE
- To run a section of code in a program:
- Highlight the section of code, and type
- matplotlib and numpy commands are directly accessible without loading their modules
- There are some important differences between working from the ipython command line and running a script. Rob Hetland says, "iPython runs in interactive mode (i.e., a draw or show at the end of each plotting command). When run as a script, python is in non-interactive mode, so that it only renders the figure when explicitly told to do so. This makes scripts faster, as intermediate renderings are not done." This is why the plt.show() command is required at the end of a plotting script.
- dir(whatever) gives names of methods defined for whatever (could be an object, module, or method)
- typing nc. then TAB will give a listing of all the functions in nc (but in the Canopy IDE dir(nc) is MUCH better)
- help(nc.DataSet) help on the function nc.Dataset
- whos gives a list of all objects (variables, functions, modules)
- object? gives info on any object
- reset clears the workspace (except of loaded modules)
- reset -f clears the workspace without asking for confirmation
- import my_lib to import my own module my_lib.py
- reload(my_lib) is needed if you have edited my_lib.py
- McKinney (2013) Python for Data Analysis. O'Reilly, 452 pp. This is my favorite book so far. It has chapters on NumPy and Matplotlib. Also, he is the guy who created Pandas, a surprisingly useful module for messy data jobs like working with spreadsheets. The Appendix on Python Language Essentials is also a great reference for python itself.
- Donaldson (2009) Visual QuickStart Guide, Python, 2nd Edition. Peachpit Press. A reasonable place to start reading your way into python.