Skip to main content
Skip table of contents

Installing Python Modules and Packages

Seeq Data Lab provides a controlled environment to ensure stability and security for your data analysis projects. This means users do not have sudo privileges within the Data Lab project itself, and therefore cannot use typical package managers like apt-get or yum to install OS packages.

Overview

Python packages found in the public PyPi repository can be installed both to the current Data Lab project or all projects either directly in a notebook or a Data lab terminal. See Preinstalled Packages for a list of preinstalled packages and our recommendation to use them.

Installing Packages From a Notebook

Install a package for the the current Python kernel from within a notebook by using the following command in a notebook code cell.

CODE
!pip install <package>

You must restart the kernel after installing the package in a notebook for the package to be imported when referenced in a notebook cell. Restart the kernel by clicking on the menu Kernel > Restart (It is a common mistake to forget!)

If the installation fails to complete, please check the requirements for the specific Python package to ensure all requirements are met by the Data Lab server and/or project.

Switch Python Versions Within Your Notebook

Data Lab provides a user-friendly way to switch Python versions within your notebook. Simply navigate to the kernels dropdown menu situated in the top right corner of your notebook (1). This will open a dropdown that list the available Python versions to select from (2). The Python version you choose for a particular notebook cell is automatically persisted after execution. This eliminates the need to repeatedly select the version for each cell within the same notebook.

The Python version for the notebook is only saved after executing a cell in the notebook.

image-20240327-210106.png

Installing Packages From a Terminal

When installing, uninstalling or listing Python packages, it’s often more convenient to use a terminal. You can launch a terminal by clicking on the menu New > Terminal. Once you’re inside the terminal, you don’t have to precede the commands with an exclamation point.

CODE
pip install <package>

Make sure to restart the kernel of any open notebooks after the package has been installed through the terminal.

Changing Python Versions

The pyversion command empowers you to manage Python versions directly from the terminal. To switch to Python 3.11, simply execute the command pyversion 3.11. This ensures that subsequent package installations using pip install target the newly selected Python version (3.11 in this case).

image-20240327-210357.png

The activated Python version is depicted between parentheses, “(pyX.Y.Z)”, in the command line and will Initially defaults to the platform's default Python version, which will be 3.8 until the October 2024 update. In the example above you can see that the version is py3.8.18

Some modules are preinstalled in Data Lab. For example, Pandas and NumPy are always available and you can inspect the version by doing:

CODE
pip show <package_name>

You can upgrade or downgrade these packages to a specific version. For example:

CODE
pip install pandas==1.1.3

Packages that are specific to your project are installed to the ~/.local/lib/pythonX.YY/site-packages folder. Where X.YY is the Python version being used. Sometimes pip will have trouble installing or uninstalling a package and leave you in a bad state. You can always cd to this folder and use rm -rf <folder_name> to manually remove packages.

Upgrading SPy

The SPy module is packaged as seeq-spy, and you can easily upgrade it by issuing the following command:

CODE
pip install -U seeq-spy

This command will override the built-in version for this project only and this version will remain even if Data Lab is upgraded. You can choose to revert to the built-in version of SPy by doing the following:

CODE
pip uninstall -y seeq-spy

Installing Packages Globally (to All Projects)

Admins can install Python packages globally for use in all projects by installing the package into the folder /seeq/python/global-packages. The preferred way to do this is to set the PYTHONUSERBASE environment variable to this folder and then run the desired pip command.

CODE
export PYTHONUSERBASE=/seeq/python/global-packages 
pip install <package>

Make sure to restart the kernel of any open notebooks after the package has been installed through the terminal.

To uninstall a global package:

CODE
export PYTHONUSERBASE=/seeq/python/global-packages 
pip uninstall <package>

Note that all pip commands intended to reference or include global packages must also use PYTHONUSERBASE=/seeq/python/global-packages as a prefix before the desired pip command.

CODE
export PYTHONUSERBASE=/seeq/python/global-packages 
pip show <package>
pip list

Order of Precedence for Importing Python Packages

Data Lab has 3 locations for Python packages with each location having a different priority when imported by a notebook’s kernel.

  1. Local: User installed packages into the current Data Lab project have the highest priority when a notebook attempts to import a package or module.

  2. Global: Admins who have installed packages globally for all projects to access have the next priority level when a notebook attempts to import a package or module.

  3. System: Preinstalled packages have the lowest priority when a notebook attempts to import a package or module.

Installing JupyterLab Extensions

Data Lab’s Advanced Mode is built on JupyterLab, and there are many useful extensions that the community has developed. Data lab supports both Jupyter “lab” extensions which adds additional user interface capabilities to JupyterLab as well as Jupyter “server” extensions which add backend Jupyter capabilities. Only extensions distributed as a Python package are supported. Extensions can be added on a per-project basis or globally installed. For instance, Solara can be used to build Python web applications. In the example How To: Create a Box Plot Add-on with Plotly and Solara, once Solara is installed (along with the other Python dependencies in the aforementioned link), you must restart the project for Data Lab to run the server components of Solara. You can do so by clicking the Quit button in the Data Lab header to shut down the project. Once you reopen the project, the server components will load on startup.

Sharing Configuration Across Projects Using pip.conf

To share pip configuration across all Data Lab projects, admins can create and configure a "pip.conf" file in the /seeq/python/global-packages/.config folder.

Here is an example pip.conf file:

CODE
[install]
extra-index-url = https://pypi.example.com
trusted-host = pypi.example.com

Pip config files also support a list of extra and trusted URLs. For more information, refer to the official documentation.

Installing Packages from a Private Repository

For private repository configuration, admins can also create a file “.netrc” with credentials in the /seeq/python/global-packages/.config folder. This will enable users to download packages without entering credentials.

Here is an example .netrc file:

CODE
machine pypi.example.com
    login your_pipy_example_com_login
    password your_pipy_example_com_password
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.