Working with packages

How to work with packages

DataLab is preconfigured with a recent version of Python and R and a host of commonly used data science and machine learning packages.

On top of that you can install additional packages or different versions of the pre-installed packages right from any notebook.

Browsing pre-installed packages

Installing additional packages

If a package you want to use is not pre-installed, you can install it yourself using as described below.

Note that you need to reinstall packages every time your workbook session is restarted, which happens 5 minutes after closing the workbook tab or after 30 minutes of inactivity on the free plan.

To make this easy, keep track of additional package installs at the top of your notebook, so you can easily rerun the commands when you return to your workbook.

Python

To install additional packages, add !pip install <name-of-pkg> e.g. !pip install pythonwhat in a code cell. If you want to install a specific version of a package, including the ones that come pre-installed, use !pip install <name-of-pkg>==<wanted-version>.

If you want to suppress the output when installing additional packages, you can use %%capture in the line above the !pip command:

%%capture
!pip install PyPortfolioOpt==1.4.2

R

If you want to suppress the output when installing additional packages, you can use the quiet = TRUE argument:

install.packages("PortfolioAnalytics", quiet = TRUE)

You can also use suppressMessages(), suppressWarnings() and suppressPackageStartupMessages() to suppress output.

Resolving issues

If you encounter problems when installing packages, let us know through one of the channels described in Get help.

Due to security reasons, currently not all packages can be installed.

In particular installing packages with native dependencies might fail partially or completely due to a lack of permissions to execute certain installation steps.

Last updated