The code is hosted in a Git Repository:
https://devhub.cisco.com/sf/projects/cosc_learning_labs/
(You will be re-directed to the login page if you are not already logged in to that website.)
You need to perform a git clone of the code from the Git Repository. This can be done in a command shell, as shown below. Alternatively, there are other ways of achieving this. For example, an IDE, such as Eclipse, can do this for you.
From the command line of a shell, the clone is performed by a single command:
git clone ssh://<you>@gerrit-open1.cisco.com:29418/cosc-learning-labs
where <you>
is your username as registered with the website.
This will create directory
cosc-learning-labs
in the current directory.
The convention is for the current directory to be named git
, but that is your choice.
If you need to download the git
command, visit this website:
Change the current directory to the sub-directory:
cosc-learning-labs/src/learning_lab
The shell command is usually either:
cd cosc-learning-labs/src/learning_lab
or
cd cosc-learning-labs\src\learning_lab
You need Python to be available. To download Python, visit website:
Due to the popularity of Python, many operating systems have pre-packaged it.
For Ubuntu, Python can be installed using apt-get:
sudo apt-get install python
For OSX, visit website:
The Python website offers two major versions of Python: 3.x.x
and 2.x.x
. The version of Python employed by this Learning Lab is revealed by the following command:
In [6]:
import sys
print(sys.version)
The command above was run inside an IPython Notebook. In a command line shell use:
python --version
The following Python libraries are required:
The command to install a Python library is usually:
pip install <library>
or
easy_install <library>
You will probably need to prefix these commands with sudo
on a Linux OS. For example:
sudo pip install lxml
The conventional Python interactive shell is entered with the command:
python
The response will be something like:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
The
>>>
is the prompt to enter Python code, for example:
>>> print('Hello, World!')
Hello, World!
>>>
To verify that the 3rd party libraries are available, we import them into the Python Interactive Shell.
In [7]:
import lxml
import requests
Enter the name of an imported module to see a description of it...
In [8]:
lxml
Out[8]:
In [9]:
requests
Out[9]:
There is a plug-in for Eclipse IDE, named PyDev, that offers a Python Interactive Shell in the Console view. You can this as an alternative to the Python Interactive Shell, described above.
When the PyDev Console is opened, you will see something similar to:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev -- Python IDE for Eclipse
For help on using PyDev's Console see http://pydev.org/manual_adv_interactive_console.html
PyDev console: using IPython 2.3.1
>>>
/usr/bin/python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]
>>>
Note the familiar prompt where you can enter Python code.
>>>
The update site for PyDev is http://pydev.sf.net/updates/
PyDev for Eclipse, as shown above, uses IPython. Jupyter is the new name for IPython. The installation web page is http://ipython.org/install.html.
All the web pages for this Learning Lab are available as IPython Notebooks.
Assuming that your current directory is:
learning_lab
as per the instructions above, you can list the IPython Notebooks:
In [10]:
ls *.ipynb
To use these Notebooks, start IPython with the command:
ipython notebook
and it will open a web page that offers you a list of hyper-links to the Notebooks, including the document you are currently reading!
The advantage of IPython Notebooks is that they already contain the Python sample code, sparing you the chore of typing it yourself, or repetitive copy-and-paste.
The final step is to import the Learning Lab module into your Python Interactive Shell.
In [11]:
import learning_lab
To confirm that the module is imported, use the 'help' command to describe the module:
In [12]:
help(learning_lab)