On CoCalc I think we explicitly patch the Sage we provide to include ~/.local:
~$ sage --python3 -c "import sys; print(sys.path)"
['', '/ext/sage/sage-9.3/local/lib/python39.zip',
'/ext/sage/sage-9.3/local/lib/python3.9',
'/ext/sage/sage-9.3/local/lib/python3.9/lib-dynload',
'/home/user/.local/lib/python3.9/site-packages',
'/ext/sage/sage-9.3/local/lib/python3.9/site-packages',
'/ext/sage/sage-9.3/local/lib/python3.9/site-packages/awalipy-0.4-py3.9-linux-x86_64.egg']
Also note that all the other path entries are our sage install (not
the system python, which is crazy, as you point out).
For us, it's very very important that "pip install --user" just works.
Also, for us, usually people are working in a very clean well defined
environment (a cocalc project), which they are using for a very
specific "project" (e.g., teaching or taking a specific class, or
writing a paper), so using ~/.local is very reasonable. I see at
[1] that our page about installing packages "into sage is not
supported", and it should be updated to say that "sage --pip install"
does work. We also make pip default to --user so actually "pip
install" does just work.
I just found a "random" package on pypi:
~$ sage --pip install pytype
Defaulting to user installation because normal site-packages is not writeable
Collecting pytype
...
~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.3, Release Date: 2021-05-09 │
│ Using Python 3.9.2. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pytype
sage: # yeah
IMHO, this is pretty good user experience.
Sometimes people do break their sage installs via installing stuff
into ~/.local, but it's also easy to fix by just deleting ~/.local
and starting over, and it's usually very clear this is the problem
based on the traceback.
-- William