How to import python libraries installed with --user option

on a shared linux system, if I install pip_install a python package I get this error

>>> pip_install('scipy')
Collecting scipy
  Using cached
Requirement already satisfied: numpy>=1.13.3 in /data/home/apps/Slicer-4.11.0-2020-01-30-linux-amd64/lib/Python/lib/python3.6/site-packages (from scipy) (1.17.3)
Installing collected packages: scipy
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/home/apps/Slicer-4.11.0-2020-01-30-linux-amd64/lib/Python/lib/python3.6/site-packages/scipy'
Consider using the `--user` option or check the permissions.

When I use the --user option, scipy is installed under ~/.local/lib/python3.6/site-packages, but I can’t import it into Slicer.

import scipy
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘scipy’

Is the only solution to install slicer into a user-writable folder?

Yes, if you want to install a package in the application tree you need to be able to write there.

Or you could try appending to sys.path before importing.

If specifically about scipy I have a Slicer PR #1254 to include Scipy in the standard build. It is a WIP as I stopped working on it after having some issues with it quietly failing due to some likely parallel build problem. Updates to this PR would be welcomed.