Skip to content

Fix inaccessible python packages after Python update w/ Conda #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/deployments/python-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ 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.

Check the [best practices](https://www.anaconda.com/using-pip-in-a-conda-environment/) on using `pip` inside `conda`.
12 changes: 12 additions & 0 deletions pkg/workloads/cortex/serve/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ fi

# install from conda-packages.txt
if [ -f "/mnt/project/conda-packages.txt" ]; then
py_version_cmd='echo $(python -c "import sys; v=sys.version_info[:2]; print(\"{}.{}\".format(*v));")'
old_py_version=$(eval $py_version_cmd)

conda install --file /mnt/project/conda-packages.txt
new_py_version=$(eval $py_version_cmd)

# reinstall core packages if Python version has changed
if [ $old_py_version != $new_py_version ]; then
echo "warning: you have changed the Python version from $old_py_version to $new_py_version; this may break Cortex's web server"
echo "reinstalling core packages ..."
pip --no-cache-dir install -r /src/cortex/serve/requirements.txt
rm -rf $CONDA_PREFIX/lib/python${old_py_version} # previous python is no longer needed
fi
fi

# install pip packages
Expand Down