Difference between revisions of "IPython"

From Storrs HPC Wiki
Jump to: navigation, search
(Add installation instructions)
(Link to PEP 370)
Line 68: Line 68:
  
 
The <code>--user</code> argument is to install the packages
 
The <code>--user</code> argument is to install the packages
to our home directory under <code>~/.local/</code>
+
to our [https://www.python.org/dev/peps/pep-0370/ home directory] under <code>~/.local/</code>
 
because we don't have write permissions to the system directory <code>/apps2/python/3.6.1/</code>.
 
because we don't have write permissions to the system directory <code>/apps2/python/3.6.1/</code>.
  

Revision as of 17:10, 13 May 2017

This article is a work in progress.

IPython is so much more useful than the typical python shell, that the first thing to as a programmer on a new computer is to install IPython before anything else! IPython gives you features like tab completion, running programs from the shell, editing files from inside python, saving history, and exploring source code among other things. Version 6 of IPython now also has static completion, so if you open square brackets you can tab-complete Python lists and dictionaries, write really long commands and use fewer temporary variables.

Don't worry if you have never programmed with Python before. The language is fun to learn. Learning python is beyond the scope of this guide, so feel free to consult the resources in the sidebar of the Python subreddit. If you need help and are new to programming in general, you can post to Learn Python or contact the HPC admins if your question is cluster related.

Requirements for this guide:

  • Some experience with the shell
  • Some experience with any programming language

Learning objectives:

  • Creating macros
  • Running python programs
  • Building up a script
  • Debugging errors

This introduction to IPython is part of the HPC intermediate workshop.

Install IPython

First check the version of Python you are currently using.

python --version
#> Python 2.6.6

The operating system version of Python 2.6.6 is ancient, so if that's the version you have by default, you should load a more recent version. We need Python 3.4 or later for IPython 6's static code completion, so let's use the latest python 3.6.1:

module -t avail python
module load python/3.6.1
python --version
#> Python 3.6.1

I promise that is the last time we will use python ^_~

Now we can install IPython:

pip3 install --user ipython
#> Successfully installed decorator-4.0.11 ipython-6.0.0 ipython-genutils-0.2.0 jedi-0.10.2 pexpect-4.2.1 pickleshare-0.7.4 prompt-toolkit-1.0.14 ptyprocess-0.5.1 pygments-2.2.0 simplegeneric-0.8.1 traitlets-4.3.2 wcwidth-0.1.7

The --user argument is to install the packages to our home directory under ~/.local/ because we don't have write permissions to the system directory /apps2/python/3.6.1/.

Now IPython is installed! But if we try to run ipython we get an error because it is not yet in the $PATH:

ipython
#> -bash: ipython: command not found

Let's edit our ~/.bashrc so that the shell knows where to search for the program:

echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
which ipython
#> ~/.local/bin/ipython