Skip to content

Commit 1679e68

Browse files
committed
venv on top of uenv
1 parent 1b2c1d0 commit 1679e68

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

docs/guides/storage.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,13 @@ The first step is to create the virtual environment using the usual workflow.
203203
# and other useful tools
204204
uenv start prgenv-gnu/24.11:v1 --view=default
205205

206+
# unset PYTHONPATH and set PYTHONUSERBASE to avoid conflicts
207+
unset PYTHONPATH
208+
export PYTHONUSERBASE=/user-environment/env/default
209+
206210
# create and activate a new relocatable venv using uv
207211
# in this case we explicitly select python 3.12
208-
uv venv -p 3.12 --relocatable --link-mode=copy /dev/shm/sqfs-demo/.venv
212+
uv venv -p /user-environment/env/default/bin/python --system-site-packages --relocatable --link-mode=copy /dev/shm/sqfs-demo/.venv
209213
# You can also point to the uenv python with `uv venv -p $(which python) ...`
210214
# which, among other things, enables user portability of the venv
211215
cd /dev/shm/sqfs-demo
@@ -231,12 +235,16 @@ The first step is to create the virtual environment using the usual workflow.
231235
# and other useful tools
232236
uenv start prgenv-gnu/24.11:v1 --view=default
233237

238+
# unset PYTHONPATH and set PYTHONUSERBASE to avoid conflicts
239+
unset PYTHONPATH
240+
export PYTHONUSERBASE=/user-environment/env/default
241+
234242
# for the example create a working path on SCRATCH
235243
mkdir $SCRATCH/sqfs-demo
236244
cd $SCRATCH/sqfs-demo
237245

238246
# create and activate the empty venv
239-
python -m venv ./.venv
247+
python -m venv --system-site-packages ./.venv
240248
source ./.venv/bin/activate
241249

242250
# install software in the virtual environment

docs/software/ml/pytorch.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,15 @@ $ exit # (6)!
810810
Python virtual environments can be slow on the parallel Lustre file system due to the amount of small files and potentially many processes accessing it.
811811
If this becomes a bottleneck, consider [squashing the venv][ref-guides-storage-venv] into its own memory-mapped, read-only file system to enhance scalability and reduce load times.
812812

813-
??? bug "Python packages from uenv shadowing those in a virtual environment"
814-
When using uenv with a virtual environment on top, the site-packages under `/user-environment` currently take precedence over those in the activated virtual environment. This is due to the uenv paths being included in the `PYTHONPATH` environment variable. As a consequence, despite installing a different version of a package in the virtual environment from what is available in the uenv, the uenv version will still be imported at runtime. A possible workaround is to prepend the virtual environment's site-packages to `PYTHONPATH` whenever activating the virtual environment.
813+
??? bug "Python packages from uenv view shadowing those in a virtual environment"
814+
Some uenv views set the `PYTHONPATH` environment variable and/or do not set the `PYTHONUSERBASE` environment variable.
815+
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.
816+
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]:
815817
```bash
816-
export PYTHONPATH="$(python -c 'import site; print(site.getsitepackages()[0])'):$PYTHONPATH"
818+
unset PYTHONPATH
819+
export PYTHONUSERBASE=/user-environment/env/default
817820
```
818-
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.
821+
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.
819822

820823
!!! note
821824
Keep in mind that

docs/software/uenv/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ Views are loaded using the `--view` flag for `uenv start` (also for `uenv run` a
334334
$ uenv start --view=prgenv-gnu:default,editors:ed prgenv-gnu/24.11:v1,editors
335335
```
336336

337+
!!! info
338+
Python virtual environments can be created on top of a uenv view.
339+
However, to ensure that the Python interpreter and packages from the uenv view are used, the `PYTHONPATH` and `PYTHONUSERBASE` environment variables must be set correctly, see our guide on [Python virtual environments with uenv][ref-guides-storage-venv].
340+
337341
#### Modules
338342

339343
Most uenv provide the modules, that can be accessed using the `module` command.

0 commit comments

Comments
 (0)