Skip to content
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

Disable user site packages (~/.local) for specific in-container Python components #1959

Closed
achimnol opened this issue Mar 15, 2024 · 2 comments · Fixed by #1962
Closed

Disable user site packages (~/.local) for specific in-container Python components #1959

achimnol opened this issue Mar 15, 2024 · 2 comments · Fixed by #1962
Labels
comp:agent Related to Agent component type:enhance Enhance component, behavior, internals without user-facing features urgency:3 Must be finished within a certain time frame.
Milestone

Comments

@achimnol
Copy link
Member

achimnol commented Mar 15, 2024

When users install custom Python packages into the user-site directory (~/.local) which is provided as an auto-mounted docker volume in containers, sometimes they break the dependency of Jupyter making it to crash when starting the app.

We could minimize the impact of dependency breakage due to user-installed packages as follows:
image

However, it is not possible to 100% prevent such problems because we cannot disable user-site directories for specific packages for a single Python process running both ipykernel and user programs.

Note

Some futuristic idea: We could make ipykernel to use subinterpreters in Python 3.12+ to isolate the package import namespaces (with different user-site settings) within a single process.

Still, I think it would be better to explicitly disable user-sites for the designated components to minimize the problem's surface area.

@achimnol achimnol added comp:agent Related to Agent component type:enhance Enhance component, behavior, internals without user-facing features urgency:3 Must be finished within a certain time frame. labels Mar 15, 2024
@achimnol achimnol added this to the 24.03 milestone Mar 15, 2024
@achimnol
Copy link
Member Author

achimnol commented Mar 15, 2024

Some investigation results:

  • ipykernel still depends on too significant portion of the Jupyter package ecosystem, including juypter_client and jupyter_core, which are the frequent breakers.
  • Python's import order prefers venv packages first, and then read user-site packages, and then falls back to the system-site packages. Therefore, if we apply virtualenvs in the image-provided Python setups, we can no longer provide the .local-based runtime customization of container environments.

So, I'm closing this issue but keep it as a historical record for now.
We need a proper isolation mechanism implemented in the ipython-side to separate the package spaces.

@achimnol
Copy link
Member Author

Reopening this issue with a shrinked scope: let's disable the user-site directory only for the krunner itself, not the user-executed service apps which use the container's own python runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:agent Related to Agent component type:enhance Enhance component, behavior, internals without user-facing features urgency:3 Must be finished within a certain time frame.
Projects
None yet
1 participant