Skip to content

Commit 32343f2

Browse files
authored
Fix inaccessible python packages after Python update w/ Conda (#1052)
1 parent a40b678 commit 32343f2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: docs/deployments/python-packages.md

+2
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ conda-forge::pygpu
7878

7979
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`.
8080

81+
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.
82+
8183
Check the [best practices](https://www.anaconda.com/using-pip-in-a-conda-environment/) on using `pip` inside `conda`.

Diff for: pkg/workloads/cortex/serve/run.sh

+12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ fi
4242

4343
# install from conda-packages.txt
4444
if [ -f "/mnt/project/conda-packages.txt" ]; then
45+
py_version_cmd='echo $(python -c "import sys; v=sys.version_info[:2]; print(\"{}.{}\".format(*v));")'
46+
old_py_version=$(eval $py_version_cmd)
47+
4548
conda install --file /mnt/project/conda-packages.txt
49+
new_py_version=$(eval $py_version_cmd)
50+
51+
# reinstall core packages if Python version has changed
52+
if [ $old_py_version != $new_py_version ]; then
53+
echo "warning: you have changed the Python version from $old_py_version to $new_py_version; this may break Cortex's web server"
54+
echo "reinstalling core packages ..."
55+
pip --no-cache-dir install -r /src/cortex/serve/requirements.txt
56+
rm -rf $CONDA_PREFIX/lib/python${old_py_version} # previous python is no longer needed
57+
fi
4658
fi
4759

4860
# install pip packages

0 commit comments

Comments
 (0)