Conda environment revision rollback limits with mixed pip installations
0 reputation · 15 Jul 2023, 01:00 UTC
0 reputation · 15 Jul 2023, 01:00 UTC
Conda provides a mechanism to revert an environment to a previous state using the --revision flag with the conda install command. This process relies on the local history stored in the environment's metadata to reinstall a specific set of packages.
A significant uncertainty exists when environments utilize both conda and pip. While conda tracks its own package changes in the revision log, pip-installed packages are not recorded in this history. Consequently, rolling back to a previous conda revision does not remove or revert packages installed via pip that were added after that revision point.
This behavior creates a potential mismatch between the restored conda package set and the remaining pip-installed dependencies, which may lead to version conflicts or unexpected runtime behavior.
No, the conda revision system does not provide a native mechanism to synchronize, remove, or revert pip-installed packages during a rollback. The --revision flag operates exclusively on the conda metadata history; because pip manages its own package state independently, pip-installed dependencies are invisible to the conda rollback process.
When a conda rollback reinstalls a package that conflicts with a pip-installed version, the environment enters a "shadowed" state. Both versions may physically exist within the site-packages directory, but Python's import mechanism will only load one.
sys.path is imported. In most conda environments, conda-managed packages take precedence over those installed via pip.ImportError, AttributeError, or silent runtime failures if the pip package has modified shared dependencies.Since conda cannot automate pip recovery, you must manage the pip state manually. To ensure a consistent environment after a rollback, follow these steps:
pip freeze > pre_rollback_requirements.txtconda install --revision [N]pip uninstall -r pre_rollback_requirements.txtTo verify if a pip package is shadowing a restored conda package, run the following command to check the installation path of the imported module:
python -c "import [package_name]; print([package_name].__file__)"
If the path points to a site-packages location not managed by the restored conda revision, the pip version is still present and potentially conflicting.
Diagnostic Detail: Are you using a conda-forge based environment or the defaults channel? This can affect how conda handles the initial installation of packages that are also available via pip.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.