{ "cells": [ { "cell_type": "code", "execution_count": 31, "id": "c821b77e-5db8-433c-8b39-151991d40c4a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "17 17\n" ] } ], "source": [ "!conda env export > all_packages.yml\n", "!conda env export --from-history > explicit_packages.yml\n", "\n", "import yaml\n", "\n", "# Load the explicitly installed packages from history\n", "with open(\"explicit_packages.yml\", 'r') as f:\n", " explicit = yaml.safe_load(f)\n", "explicit_names = explicit[\"dependencies\"] + [\"datashader\"]\n", "\n", "# Load all the packages with their versions\n", "with open(\"all_packages.yml\", 'r') as f:\n", " all_pkgs = yaml.safe_load(f)\n", "\n", "# Filter the packages to keep only explicit ones with their versions\n", "final_deps = [pkg.rsplit(\"=\", 1)[0] for pkg in all_pkgs['dependencies'] if pkg.split(\"=\")[0] in explicit_names]\n", "\n", "# Update the dependencies\n", "explicit['dependencies'] = final_deps\n", "del explicit[\"prefix\"]\n", "\n", "# Save the combined result\n", "with open(\"environment.yml\", 'w') as f:\n", " yaml.safe_dump(explicit, f)\n", "\n", "print(len(explicit_names), len(final_deps))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.15" } }, "nbformat": 4, "nbformat_minor": 5 }