Search…
Python packages

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):
1
./my-classifier/
2
├── cortex.yaml
3
├── predictor.py
4
├── ...
5
└── requirements.txt
Copied!
If you want to use conda to install your python packages, see the Conda section 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:
1
[global]
2
extra-index-url = https://<username>:<password>@<my-private-index>.com/pip
Copied!
In same directory, create a dependencies.sh script and add the following contents:
1
cp pip.conf /etc/pip.conf
Copied!
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:
1
# requirements.txt
2
3
# public access
4
git+https://github.com/<username>/<repo name>[email protected]<tag or branch name>#egg=<package name>
5
6
# private access
7
git+https://<personal access token>@github.com/<username>/<repo name>[email protected]<tag or branch name>#egg=<package name>
Copied!
On GitHub, you can generate a personal access token by following these steps.

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:
1
./my-classifier/
2
├── cortex.yaml
3
├── predictor.py
4
├── ...
5
├── mypkg
6
│ └── __init__.py
7
├── requirements.txt
8
└── setup.py
Copied!
In this case, requirements.txt will have this form:
1
# requirements.txt
2
3
.
Copied!

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):
1
./my-classifier/
2
├── cortex.yaml
3
├── predictor.py
4
├── ...
5
└── conda-packages.txt
Copied!
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:
1
conda-forge::rdkit
2
conda-forge::pygpu
Copied!
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.
Check the best practices on using pip inside conda.
Last modified 10mo ago