LogoLogo
WebsiteSlack
0.33
0.33
  • Get started
  • Clusters
    • Management
      • Auth
      • Create
      • Update
      • Delete
      • Environments
    • Instances
      • Multi-instance
      • Spot instances
    • Observability
      • Logging
      • Metrics
    • Networking
      • Load balancers
      • VPC peering
      • HTTPS
      • Custom domain
    • Advanced
      • Setting up kubectl
      • Private Docker registry
  • Workloads
    • Realtime APIs
      • Example
      • Predictor
      • Configuration
      • Models
      • Parallelism
      • Server-side batching
      • Autoscaling
      • Statuses
      • Metrics
      • Multi-model
        • Example
        • Configuration
        • Caching
      • Traffic Splitter
        • Example
        • Configuration
      • Troubleshooting
    • Async APIs
      • Example
      • Predictor
      • Configuration
      • Statuses
      • Webhooks
      • Metrics
    • Batch APIs
      • Example
      • Predictor
      • Configuration
      • Jobs
      • Statuses
      • Metrics
    • Task APIs
      • Example
      • Definition
      • Configuration
      • Jobs
      • Statuses
      • Metrics
    • Dependencies
      • Example
      • Python packages
      • System packages
      • Custom images
  • Clients
    • Install
    • Uninstall
    • CLI commands
    • Python client
Powered by GitBook
On this page
  • PyPI packages
  • Private PyPI packages
  • GitHub packages
  • Installing with Setup
  • Conda packages
  • Customizing Dependency Paths
  1. Workloads
  2. Dependencies

Python packages

PreviousExampleNextSystem packages

Last updated 4 years ago

PyPI packages

You can install your required PyPI packages and import them in your Python files using pip. Cortex looks for a requirements.txt file in the top level Cortex project directory (i.e. the directory which contains cortex.yaml):

./my-classifier/
├── cortex.yaml
├── predictor.py
├── ...
└── requirements.txt

If you want to use conda to install your python packages, see the below.

Note that some packages are pre-installed by default (see "pre-installed packages" for your Predictor type in the Realtime API Predictor documentation and Batch API Predictor documentation).

Private PyPI packages

To install packages from a private PyPI index, create a pip.conf inside the same directory as requirements.txt, and add the following contents:

[global]
extra-index-url = https://<username>:<password>@<my-private-index>.com/pip

In same directory, create a and add the following:

cp pip.conf /etc/pip.conf

You may now add packages to requirements.txt which are found in the private index.

GitHub packages

You can also install public/private packages from git registries (such as GitHub) by adding them to requirements.txt. Here's an example for GitHub:

# requirements.txt

# public access
git+https://github.com/<username>/<repo name>.git@<tag or branch name>#egg=<package name>

# private access
git+https://<personal access token>@github.com/<username>/<repo name>.git@<tag or branch name>#egg=<package name>

Installing with Setup

Python packages can also be installed by providing a setup.py that describes your project's modules. Here's an example directory structure:

./my-classifier/
├── cortex.yaml
├── predictor.py
├── ...
├── mypkg
│   └── __init__.py
├── requirements.txt
└── setup.py

In this case, requirements.txt will have this form:

# requirements.txt

.

Conda packages

Cortex supports installing Conda packages. We recommend only using Conda when your required packages are not available in PyPI. Cortex looks for a conda-packages.txt file in the top level Cortex project directory (i.e. the directory which contains cortex.yaml):

./my-classifier/
├── cortex.yaml
├── predictor.py
├── ...
└── conda-packages.txt

The conda-packages.txt file follows the format of conda list --export. Each line of conda-packages.txt should follow this pattern: [channel::]package[=version[=buildid]].

Here's an example of conda-packages.txt:

conda-forge::rdkit
conda-forge::pygpu

In situations where both requirements.txt and conda-packages.txt are provided, Cortex installs Conda packages in conda-packages.txt followed by PyPI packages in requirements.txt. Conda and Pip package managers install packages and dependencies independently. You may run into situations where Conda and pip package managers install different versions of the same package because they install and resolve dependencies independently from one another. To resolve package version conflicts, it may be in your best interest to specify their exact versions in conda-packages.txt.

The current version of Python is 3.6.9. Updating Python to a different version is possible with Conda, but there are no guarantees that Cortex's web server will continue functioning correctly. If there's a change in Python's version, the necessary core packages for the web server will be reinstalled. If you are using a custom base image, any other Python packages that are built in to the image won't be accessible at runtime.

Customizing Dependency Paths

Cortex allows you to specify different dependency paths other than the default ones. This can be useful when deploying different versions of the same API (e.g. CPU vs GPU dependencies).

To customize the path for your dependencies, you can specify predictor.dependencies in your API's configuration file. You can set one or more fields to specify the path for each dependency type. Each path should be a relative path with respect to the current file.

For example:

# cortex.yaml

- name: my-classifier
  kind: RealtimeAPI
  predictor:
    (...)
    dependencies:
      pip: requirement-gpu.txt
      conda: conda-packages-gpu.txt
      shell: dependencies-gpu.sh

On GitHub, you can generate a personal access token by following .

Check the on using pip inside conda.

these steps
best practices
dependencies.sh script
Conda section