Customizing pip settings

You can add custom packages from the Python Package Index, PyPI without access to the public network.

You can use these methods to add custom packages:

Required roles:

  • You must be a Cloud Pak for Data cluster administrator to create a pip configuration file pip.conf.
  • You need Admin or Editor permissions on the deployment space to create a custom software specification and package extension.

Before you begin

Make sure that the cc-home storage volume exists and set the MY_TOKEN environment variable. For instructions, see Setting up a storage volume to store customizations for common core services.

Configuring pip to use a proxy server

You can configure pip for use behind a proxy server by creating your own clusterwide pip configuration file that is called pip.conf in which you can specify your own package index or a proxy user.

  1. Create a pip configuration file or open the existing one at /cc-home/_global_/config/conda/pip.conf. The names of the settings in pip.conf are derived from the long command line option. Use the following options to configure your corporate proxy and an internal package index:

    [global]
    proxy=http://user:password@proxy_name:port
    index-url=http://internal-pip-index.internal.com/root/pypi/+simple/
    trusted-host=internal-pip-index.internal.com
    
  2. Retrieve any existing pip.conf files by running:

    curl -fSsk ${CPD_URL}/zen-volumes/cc-home/v1/volumes/files/%2F_global_%2Fconfig%2Fconda%2Fpip.conf -H "Authorization: ZenApiKey ${MY_TOKEN}" > pip.conf
    
  3. Copy the pip.conf file to the shared file system:

    curl -k -X PUT \
    "${CPD_URL}/zen-volumes/cc-home/v1/volumes/files/%2F_global_%2Fconfig%2Fconda" \
    -H "Authorization: ZenApiKey ${MY_TOKEN}" \
    -H "content-type: multipart/form-data" \
    -F upFile=@pip.conf
    
    Note:

    To run this script, you must generate and export the token as the ${MY_TOKEN} environment variable. For more information, see Generating an API authorization token.

Configuring pip from IBM Cloud Pak for Data storage

You can add a custom Python distribution package to IBM Cloud Pak for Data storage and then access this package directly from within a deployment runtime though Python Function or Python Scripts deployments. Alternatively, you can add a configuration to your PVC mount with the file path to the package where it can be picked up by the deployment runtime. Users can use the conda yaml file with package extensions and custom software specifications to drive the installation of the package during deployment of the models, Python Function, or Python Scripts.

  1. Generate a distribution package.

  2. Upload the compressed archive file to /cc-home/_global_/config/conda.

    curl -k -X PUT \
    "${CPD_URL}/zen-volumes/cc-home/v1/volumes/files/%2F_global_%2Fconfig%2Fconda" \
    -H "Authorization: ZenApiKey ${MY_TOKEN}" \
    -H "content-type: multipart/form-data" \
    -F upFile=@<package_name>
    
  3. Create a pip.conf file with file path that points to the uploaded package path:

    Example for package linalgnorm:

    cat pip.conf
    [global]
    find-links = file:///cc-home/_global_/config/conda/pip_repo/linalgnorm
    
  4. Upload the pip.conf file to /cc-home/_global_/config/conda:

    curl -k -X PUT \
    "${CPD_URL}/zen-volumes/cc-home/v1/volumes/files/%2F_global_%2Fconfig%2Fconda" \
    -H "Authorization: ZenApiKey ${MY_TOKEN}" \
    -H "content-type: multipart/form-data" \
    -F upFile=@pip.conf
    
  5. Create a package extension with conda.yaml specification as shown in the example and associate the package extension with customer software specification.

    Example for package linalgnorm:

    channels:
    - defaults
    dependencies:
    - pip:
    - linalgnorm
    
    Note:

    To run this script, you must generate and export the token as the ${MY_TOKEN} environment variable. For more information, see Generating an API authorization token.

Parent topic: Customizing with third-party and private Python libraries