Skip to content

Conversation

@boeschf
Copy link
Contributor

@boeschf boeschf commented Nov 5, 2025

@github-actions

This comment was marked as outdated.

1 similar comment
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment was marked as outdated.

@github-actions

This comment has been minimized.

@github-actions

This comment was marked as outdated.

@boeschf boeschf marked this pull request as ready for review November 5, 2025 12:14
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

# in this case we explicitly select python 3.12
uv venv -p 3.12 --relocatable --link-mode=copy /dev/shm/sqfs-demo/.venv
# in this case we explicitly select the python interpreter from the uenv view
uv venv -p /user-environment/env/default/bin/python --system-site-packages --relocatable --link-mode=copy /dev/shm/sqfs-demo/.venv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use -p $(which python) --system-site-packages to be a little bit more portable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we quickly explain why --system-site-packages is used?

Copy link
Contributor

@lukasgd lukasgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! When reviewing this, I felt that we have general instructions for building virtual environments on top of base environments (be it uenv or containers) in multiple locations (Connecting to Alps > Jupyter, Applications and Frameworks > ML > Pytorch, Guides > Storage > Many small files vs. HPC File Systems) that are not necessarily that easy to find for a user. Would it make sense to work on merging these instructions to a single section under e.g. Environments?

Comment on lines 207 to 208
unset PYTHONPATH
export PYTHONUSERBASE=/user-environment/env/default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably break the Jupyterlab setup

--user --name="<kernel-name>"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work in all cases - can you confirm @lukasgd ?

python -m ipykernel install --sys-prefix --name mykernel ${VIRTUAL_ENV:+--env PATH $PATH --env VIRTUAL_ENV $VIRTUAL_ENV}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this? I'm not sure if this works with just a uenv when not using a virtual env on top. Also, would kernels still be conveniently listed for selection when opening Jupyterlab (as they are with --user)? Adding cc @rsarm @twrobinson if you'd like to comment.


# unset PYTHONPATH and set PYTHONUSERBASE to avoid conflicts
unset PYTHONPATH
export PYTHONUSERBASE=/user-environment/env/default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above regarding Jupyterlab

Comment on lines 813 to 821
??? bug "Python packages from uenv view shadowing those in a virtual environment"
Some uenv views set the `PYTHONPATH` environment variable and/or do not set the `PYTHONUSERBASE` environment variable.
This can lead to unexpected behavior when using Python virtual environments on top of the uenv, as the packages installed in the uenv view may take precedence over those in the virtual environment.
A possible workaround is to unset the `PYTHONPATH` and set the `PYTHONUSERBASE` environment variables, as described in the [Python virtual environments with uenv guide][ref-guides-storage-venv]:
```bash
export PYTHONPATH="$(python -c 'import site; print(site.getsitepackages()[0])'):$PYTHONPATH"
unset PYTHONPATH
export PYTHONUSERBASE=/user-environment/env/default
```
It is recommended to apply this workaround if you are constrained by a Python package version installed in the uenv that you need to change for your application.
It is recommended to apply this workaround if you are constrained by a Python package version installed in the uenv view that you need to change for your application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above for conflict with Jupyterlab docs. We've covered this issue in multiple places in the docs, including

??? bug "Python packages from uenv shadowing those in a virtual environment"
and
??? bug "Python packages from uenv shadowing those in a virtual environment"

Overall, I think it would be good to have a consistent recommendation.

Copy link
Member

@bcumming bcumming Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it time to create a central "using Python with uenv" documentation that these pages can refer to?

That might be beyond the scope of this update - but we can do it later this quarter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, or overall central "How to extend Python base environments with venvs" also including the CE, cf. #296 (review)

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

preview available: https://docs.tds.cscs.ch/296

@boeschf
Copy link
Contributor Author

boeschf commented Nov 7, 2025

  • added a section about venvs on top of uenvs in the main uenv chapter: https://docs.tds.cscs.ch/296/software/uenv/#python-virtual-environments-on-top-of-uenv-views and attempted to refer to this section from other places
  • don't know enough about Jupyterlab - but --user installs will not work with the currently recommended environment variables
  • not going to write further documentation of venvs on top of containers - I agree that this should be addressed in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants