How to install packages from PyPI mirror on Red Hat OpenShift AI (RHOAI) workbenches in disconnected environment

Solution Unverified - Updated

Environment

  • Red Hat OpenShift AI (RHOAI)
    • Version: < 2.8

Issue

When trying to install Python packages in a Red Hat OpenShift AI (RHOAI) workbench in a disconnected environment, the pip command might fail because the connection cannot install packages from external URLs.

Resolution

You can resolve the issue in any of the following ways:

Method 1: Specify the PyPI server URL directly in the notebook cell

Specify the Python package index (PyPI) server URL directly in the pip install commands in the notebook cell, as follows:

pip install -i <private-pypi-server-url> --trusted-host <private-pypi-server-domain> python-pypi-mirror

Example:

pip install -i https://pypi-notebook.example.com --trusted-host pypi-notebook.example.com python-pypi-mirror

Method 2: Use environment variables to specify the PyPI server
Set the PIP_INDEX_URL and PIP_TRUSTED_HOST environment variables as follows:

  1. Ensure that the workbench is stopped.
  2. Edit the workbench as described in This content is not included.Updating a project workbench, and add the following Config Map environment variables:
PIP_INDEX_URL: https://pypi-notebook.example.com/simple
PIP_TRUSTED_HOST: pypi-notebook.example.com
  1. Restart the workbench.
  2. In the workbench terminal, run the following command and verify that the variables are set correctly.
pip config debug
 Example output:
env_var:
    PIP_INDEX_URL='https://pypi-notebook.example.com/simple'
    PIP_NO_CACHE_DIR='off'
    PIP_TRUSTED_HOST='pypi-notebook.example.com'
env:
    global:
      /etc/xdg/pip/pip.conf, exists: False
      /etc/pip.conf, exists: False
    site:
      /opt/app-root/pip.conf, exists: False
    user:
      /opt/app-root/src/.pip/pip.conf, exists: False
      /opt/app-root/src/.config/pip/pip.conf, exists: False

Method 3: Create a temporary pip.conf file in the workbench
Create a temporary pip.conf file in the workbench by adding the following commands to a notebook cell:

mkdir -p /opt/app-root/src/.pip

cat <<EOF > /opt/app-root/src/.pip/pip.conf
[global]
index-url = https://pypi-notebook.example.com/simple
trusted-host = pypi-notebook.example.com
EOF

Note that this workaround is valid only during the current session of the notebook.

Method 4: Create the pip.conf file in the Notebook Custom Resource (CR)

  1. Create a config map that contains the pip.conf specification, as shown in the following example:

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: pip-config
    data:
      pip.conf: |-
        [global]
        index-url = https://pypi-notebook.example.com/simple
        trusted-host = pypi-notebook.example.com
    
  2. Use the oc client to edit the Notebook CR as follows:
    oc edit notebook <notebook-name> -n <data-science-project>

  3. In the Notebook CR, find the container specification of the Notebook CR, and add the following updates:

    • In the spec > container > notebook section:
    env:  
      - name: PIP_CONFIG_FILE
        value: /opt/app-root/pip/pip.conf
    volumeMounts:
      - mountPath: /opt/app-root/pip/
        name: pip-config
    
    • In the spec > volumes section:
    volumes:
      - name: pip-config
        configMap:
          name: pip-config
          items:
            - key: pip.conf
              path: pip.conf
    

When you use any of these methods to configure the workbench with a connection to a private PyPI mirror, the pip install commands can contact the private server.

See also:

Root Cause

Workbenches must be specially configured to enable Python pip commands to use private PyPI mirrors. That configuration is not yet included in the Red Hat OpenShift AI workbench installation.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.