Packages

Pineapple is a self-contained application that includes a copy of Python 2.7. Upon installation, several useful packages are already installed and available for use without further setup. In addition, Pineapple includes commands to help you manage your Python packages.

Preinstalled packages

All of the Python 2.7 standard library packages are available.

The following packages are pre-installed:

  • numpy
  • matplotlib
  • IVisual

In [1]:
import pineapple
%pip freeze


backports.ssl-match-hostname==3.4.0.2
certifi==2015.9.6.2
Cython==0.23.2
decorator==4.0.2
funcsigs==0.4
functools32==3.2.3.post2
ipykernel==4.0.3
ipython==4.0.0
ipython-genutils==0.1.0
IVisual-alt==0.2.3
Jinja2==2.8
jsonschema==2.5.1
jupyter-client==4.0.0
jupyter-core==4.0.4
MarkupSafe==0.23
matplotlib==1.4.3
mistune==0.7.1
mock==1.3.0
nbconvert==4.0.0
nbformat==4.0.0
nose==1.3.7
notebook==4.0.4
numpy==1.11.0.dev0+cee68d1
path.py==8.1.1
pbr==1.8.0
pexpect==3.3
pickleshare==0.5
pineapple==0.4
ptyprocess==0.5
py==1.4.30
pycurl==7.19.5
Pygments==2.0.2
pyparsing==2.0.3
pytest==2.7.2
python-dateutil==2.4.2
pytz==2015.4
pyzmq==14.7.0
simplegeneric==0.8.1
six==1.9.0
terminado==0.5
tornado==4.2.1
traitlets==4.0.0
wheel==0.24.0
/home/nwhitehead/projects/pineapple/build_py27_small/share/Pineapple/python2.7/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

All preinstalled packages

The following is the full list of packages that are pre-installed:

  • Cython
  • decorator
  • ipykernel
  • ipython
  • ipython-genutils
  • IVisual
  • Jinja2
  • jsonschema
  • jupyter-client
  • jupyter-core
  • MarkupSafe
  • matplotlib
  • mistune
  • mock
  • nbconvert
  • nbformat
  • nose
  • notebook
  • numpy
  • path.py
  • pexpect
  • pickleshare
  • pineapple
  • ptyprocess
  • py
  • pycurl
  • Pygments
  • pyparsing
  • python-dateutil
  • pytz
  • pyzmq
  • simplegeneric
  • six
  • terminado
  • tornado
  • traitlets
  • wheel

Package management

The easiest way to manage packages is to use the pineapple package.

After importing the module new magic instructions %pip and %require become available.

The %pip line magic command lets you run pip from within your notebook instead of from the command line. pip is the official tool included with Python for managing packages.

For full documentation see the official documentation.

%pip examples


In [2]:
import pineapple # required for all subsequent cells

# Use %pip line magic to list all installed packages
%pip list


backports.ssl-match-hostname (3.4.0.2)
certifi (2015.9.6.2)
Cython (0.23.2)
decorator (4.0.2)
funcsigs (0.4)
functools32 (3.2.3.post2)
ipykernel (4.0.3)
ipython (4.0.0)
ipython-genutils (0.1.0)
IVisual-alt (0.2.3)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter-client (4.0.0)
jupyter-core (4.0.4)
MarkupSafe (0.23)
matplotlib (1.4.3)
mistune (0.7.1)
mock (1.3.0)
nbconvert (4.0.0)
nbformat (4.0.0)
nose (1.3.7)
notebook (4.0.4)
numpy (1.11.0.dev0+cee68d1)
path.py (8.1.1)
pbr (1.8.0)
pexpect (3.3)
pickleshare (0.5)
pineapple (0.4)
pip (7.1.2)
ptyprocess (0.5)
py (1.4.30)
pycurl (7.19.5)
Pygments (2.0.2)
pyparsing (2.0.3)
pytest (2.7.2)
python-dateutil (2.4.2)
pytz (2015.4)
pyzmq (14.7.0)
setuptools (18.3.1)
simplegeneric (0.8.1)
six (1.9.0)
terminado (0.5)
tornado (4.2.1)
traitlets (4.0.0)
wheel (0.24.0)

In [3]:
# Use %pip line magic to download and install a specific package
%pip install unittest2


Collecting unittest2
  Using cached unittest2-1.1.0-py2.py3-none-any.whl
Collecting argparse (from unittest2)
  Using cached argparse-1.4.0-py2.py3-none-any.whl
Collecting traceback2 (from unittest2)
  Using cached traceback2-1.4.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in /home/nwhitehead/projects/pineapple/build_py27_small/share/Pineapple/python2.7/lib/python2.7/site-packages (from unittest2)
Collecting linecache2 (from traceback2->unittest2)
  Using cached linecache2-1.0.0-py2.py3-none-any.whl
Installing collected packages: argparse, linecache2, traceback2, unittest2
Successfully installed argparse-1.4.0 linecache2-1.0.0 traceback2-1.4.0 unittest2-1.1.0
/home/nwhitehead/projects/pineapple/build_py27_small/share/Pineapple/python2.7/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

In [4]:
# New package is not available for import
import unittest2

In [5]:
# You can also uninstall packages
%pip uninstall -y unittest2


Uninstalling unittest2-1.1.0:
  Successfully uninstalled unittest2-1.1.0

%require examples

The %require line magic is a streamlined way to list and install packages. With no arguments it lists all installed packages together with specific versions (pip freeze).

With arguments it ensures that the correct version of a package is available. If no version is specified then the latest version is used.

Versions can be specified using version specifiers. This lets you specify minimum versions, maximum versions, and more. See requirement specifier documentation.


In [6]:
%require unittest2
import unittest2

In [7]:
%require unittest2==1.1.0

In [8]:
%require unittest2==1.1.0 pip>=7

Best practices

For notebooks designed to be distributed to other Pineapple users, it is recommended that your notebook be tested on a fresh installation of the most recent version of Pineapple. Your notebook should start with %require commands to ensure that the correct packages are loaded. This also serves as documentation of which packages your code will use.

To ensure reproducibility, it is recommended that you specify full exact version numbers for all pure Python packages that you use. It is recommended to specify minimum versions of packages for packages that are included in Pineapple by default.

Pineapple copies

Each copy of Pineapple is self-contained. This means you can duplicate the Pineapple application, play around with packages in the copy, then delete the copy with no risk of corrupting your current installation. If you install many packages it is recommended to make a backup copy of Pineapple with all your packages installed and working for peace of mind.

New versions of Pineapple will start with preinstalled packages but will no longer have any packages you installed in the old version. The recommended way to transfer packages to the new installation is to do %require to get a list of all packages, then paste that list of packages into a %require in the new installation.


In [9]:
# On the old version to get installed packages
%require


Out[9]:
'backports.ssl-match-hostname==3.4.0.2 certifi==2015.9.6.2 Cython==0.23.2 decorator==4.0.2 funcsigs==0.4 functools32==3.2.3.post2 ipykernel==4.0.3 ipython==4.0.0 ipython-genutils==0.1.0 IVisual-alt==0.2.3 Jinja2==2.8 jsonschema==2.5.1 jupyter-client==4.0.0 jupyter-core==4.0.4 linecache2==1.0.0 MarkupSafe==0.23 matplotlib==1.4.3 mistune==0.7.1 mock==1.3.0 nbconvert==4.0.0 nbformat==4.0.0 nose==1.3.7 notebook==4.0.4 numpy==1.11.0.dev0+cee68d1 path.py==8.1.1 pbr==1.8.0 pexpect==3.3 pickleshare==0.5 pineapple==0.4 pip==7.1.2 ptyprocess==0.5 py==1.4.30 pycurl==7.19.5 Pygments==2.0.2 pyparsing==2.0.3 pytest==2.7.2 python-dateutil==2.4.2 pytz==2015.4 pyzmq==14.7.0 setuptools==18.3.1 simplegeneric==0.8.1 six==1.9.0 terminado==0.5 tornado==4.2.1 traceback2==1.4.0 traitlets==4.0.0 unittest2==1.1.0 wheel==0.24.0'

In [9]:
# On the fresh new copy of Pineapple
# Paste everything in between the single quotes
%require backports.ssl-match-hostname==3.4.0.2 certifi==2015.9.6.2 Cython==0.23.2 decorator==4.0.2 funcsigs==0.4 functools32==3.2.3.post2 ipykernel==4.0.3 ipython==4.0.0 ipython-genutils==0.1.0 IVisual-alt==0.2.3 Jinja2==2.8 jsonschema==2.5.1 jupyter-client==4.0.0 jupyter-core==4.0.4 linecache2==1.0.0 MarkupSafe==0.23 matplotlib==1.4.3 mistune==0.7.1 mock==1.3.0 nbconvert==4.0.0 nbformat==4.0.0 nose==1.3.7 notebook==4.0.4 numpy==1.11.0.dev0+cee68d1 path.py==8.1.1 pbr==1.8.0 pexpect==3.3 pickleshare==0.5 pineapple==0.4 pip==7.1.2 ptyprocess==0.5 py==1.4.30 pycurl==7.19.5 Pygments==2.0.2 pyparsing==2.0.3 pytest==2.7.2 python-dateutil==2.4.2 pytz==2015.4 pyzmq==14.7.0 setuptools==18.3.1 simplegeneric==0.8.1 six==1.9.0 terminado==0.5 tornado==4.2.1 traceback2==1.4.0 traitlets==4.0.0 unittest2==1.1.0 wheel==0.24.0

You may need to remove packages that do not have version number, such as numpy in this example which you know are already present in the new copy of Pineapple.