Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this page:

Table of Contents

...

Overview

In IDAS, Python packages can be installed in several ways:

  • Option 1: Use pip to install Python packages from the Python Package Index (PyPI)

    • This may be suitable for users who are starting to use Python and/or planning to use Python very little.

    • For details, please see the below sections in this article.

  • Option 2: Use pip and venv to create a virtual environment and install packages in that virtual environment (recommended)

    • This is a recommended option for users who plan to use Python extensively or have multiple projects using Python.

    • For details on how to use venv in IDAS, please see Python Virtual Environments.

  • Option 3: Use conda to create a conda virtual environment and install packages in that conda virtual environment (recommended)

    • This is a recommended option for users who plan to use Python extensively or have multiple projects using Python.

    • For details on how to use conda in IDAS, please see Conda.

This article outlines the steps to install Python packages using pip (Option 1 above). We also recommend using tools like conda and Python virtual environments Python Virtual Environments and Conda in IDAS to manage your projects.

Installing Python packages in Jupyter Notebook

1. First, log in to the IDAS research instance with Python. If you are a student in a class that uses Python in IDAS, follow the instructions here to access your class instance.

2. In JupyterLab, click  click the "Python 3" tile under "Notebook" to start a Jupyter notebook.Image Removed

...

3. Write the following code in a new cell of the notebook, filling in the name of the package that you want to install. Run the cell with the keyboard shortcut Shift+Enter:

Code Block
!pip3 install --upgrade package-name

Example

For example, suppose we want to install the package TheFuzz, which is available from PyPI: https://pypi.org/project/thefuzz/.

In the following screenshot, cell 1 shows the installation command and its output in a Jupyter notebook. Cells 2 and 3 test a simple example from https://pypi.org/project/thefuzz/ to ensure the package has been installed

...

Image Removed.

Click on the screenshot to view an enlarged version.

...

Installing Python packages in Terminal

1. First, log in to the IDAS research instance with Python. If you are a student in a class that uses Python in IDAS, follow the instructions here to access your class instance.

2. In JupyterLab, click  click the "Terminal" tile under "Other" to start a Terminal session.Image Removed

...

3. In Terminal, type the following command, fill in the name of the package that you want to install, and press Enter:

Code Block
python3 -m pip install --user package-name

Example

For example, suppose we want to install the package TheFuzz, which is available from PyPI: https://pypi.org/project/thefuzz/.

The following code block shows the installation command and its output in Terminal:

Code Block
grudderham@idas-research-grudderham:~$ python3 -m pip install --user thefuzz

Collecting thefuzz
  Obtaining dependency information for thefuzz from https://files.pythonhosted.org/packages/19/7d/ca50835332895beb87e663f9a610a7e0a7335b69e31177aee87acc3db9bd/thefuzz-0.20.0-py3-none-any.whl.metadata
  Downloading thefuzz-0.20.0-py3-none-any.whl.metadata (3.9 kB)
Collecting rapidfuzz<4.0.0,>=3.0.0 (from thefuzz)
  Obtaining dependency information for rapidfuzz<4.0.0,>=3.0.0 from https://files.pythonhosted.org/packages/9e/ae/33dd7c9a6f06c25dfb7e556756fb4adbcea1ec2c8c7efc8aaecb106ac882/rapidfuzz-3.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
  Downloading rapidfuzz-3.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
Downloading thefuzz-0.20.0-py3-none-any.whl (15 kB)
Downloading rapidfuzz-3.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 25.2 MB/s eta 0:00:00
Installing collected packages: rapidfuzz, thefuzz
Successfully installed rapidfuzz-3.5.2 thefuzz-0.20.0

[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip

...

Test the package with a simple example from https://pypi.org/project/thefuzz/ to ensure it has been installed:

...

Open a new Launcher page in JupyterLab:Image Removed

...


From the Launcher page, start a Jupyter notebook:Image Removed

...


Run the code from a Jupyter notebook:Image Removed

Click on the screenshot to view an enlarged version.

...

Notes about Python package installation

1. The following resources may be helpful:

2. In IDAS, Python packages that have been installed by a user are available in the user library:

Code Block
/home/HawkID/.local/lib/pythonx.x/site-packages

where HawkID is your HawkID, and pythonx.x indicates the Python version, for example, Python 3.11.

3. After installing a Python package in Terminal, if you have trouble importing the package, you might need to add your user library to the PATH environment variable.

The following steps are done in Terminal:

First, crease a .bashrc if you haven't done so before:

Code Block
touch ~/.bashrc

Add your user library to PATH:

Code Block
echo 'export PATH=$PATH:~/.local/bin' >> ~/.bashrc

And then run the following in Terminal. Note that .bashrc needs to be sourced every time you start a new Terminal session.

...

If you have any questions or comments, please contact ITS contact ITS - Research Services at research-computing@uiowa.edu.