All of the Python 2.7 standard library packages are available.
The following packages are pre-installed:
In [1]:
import pineapple
%pip freeze
The following is the full list of packages that are pre-installed:
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.
In [2]:
import pineapple # required for all subsequent cells
# Use %pip line magic to list all installed packages
%pip list
In [3]:
# Use %pip line magic to download and install a specific package
%pip install unittest2
In [4]:
# New package is not available for import
import unittest2
In [5]:
# You can also uninstall packages
%pip uninstall -y unittest2
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
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.
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]:
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.