feat: Create Individual Virtual Env for the Kernel #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow/up of #73. I originally planned to re-open that one, but this seems impossible. The change addresses #6 and #62 - at least partially.
The idea is as follows:
We first create a base venv that is not to be deleted and can be re-used easily. There we install all default packages. (Thus, the very first start after applying the change is still slow).
Then, whenever a kernel is invoked, we create another, kernel-specific, venv without any additional packages. Instead, we create a link that points to the packages installed in the base image by installing a .pth file inside its site_packages dir. This way, the derived venv has access to all packages that have been installed in the base image. The Python binary from the derived venv is used to finally start the IPython kernel. The base image is intended to stay immutable and will not be actively used. If an additional package is needed, the corresponding !pip install PACKAGE call can be executed and packages do neither pollute the system environment nor the base venv. All newly installed packages end upon the kernel-specific venv. While they are lost on exit/restart (we delete the derived venv when the kernel exists), the packages inside the base image are not.
The overall idea is coming from https://stackoverflow.com/a/75545634.
An example prompt for this is
I think (!), this could be a good baseline for addressing #67 as well. - At least, running kernels with separate environments are possible this way.