How to create a new virtual environment based on an existing sage installation

473 views
Skip to first unread message

Maarten Derickx

unread,
Mar 1, 2022, 1:45:00 PM3/1/22
to sage-support
Hi All,

I am wondering what the best way is to create a new virtual environment where I can import stuff from an already existing sage installation:

I tried the following using sage 9.5.beta9

$ sage -python3 -m venv --system-site-packages venv
$ source venv/bin/activate
(venv) $ python3
Python 3.9.9 (main, Dec 25 2021, 18:25:51)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/scratch/home/mderickx/sages/sage/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/all.py", line 126, in <module>
from sage.rings.all import *
File "/scratch/home/mderickx/sages/sage/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/rings/all.py", line 87, in <module>
...
...
File "sage/rings/polynomial/multi_polynomial_libsingular.pyx", line 1, in init sage.rings.polynomial.multi_polynomial_libsingular (build/cythonized/sage/rings/polynomial/multi_polynomial_libsingular.cpp:50020)
File "sage/libs/singular/singular.pyx", line 1558, in init sage.libs.singular.singular (build/cythonized/sage/libs/singular/singular.cpp:15747)
File "sage/libs/singular/singular.pyx", line 1525, in sage.libs.singular.singular.init_libsingular (build/cythonized/sage/libs/singular/singular.cpp:12865)
File "/scratch/home/mderickx/sages/sage/local/var/lib/sage/venv-python3.9.9/lib/python3.9/posixpath.py", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

But as you can see this new venv is not created in such a way that sage the library is useable (probably because certain sage related environment variables are not set).

So what is the best way to get around this?

Matthias Koeppe

unread,
Mar 1, 2022, 2:07:50 PM3/1/22
to sage-support
The particular error that you are running into comes from Singular not being in PATH.

Use "sage -sh" to enter a shell in which SAGE_LOCAL/bin has been added to PATH.
Then you can activate the venv as you did before.

Matthias Koeppe

unread,
Mar 12, 2022, 1:21:32 PM3/12/22
to sage-support
https://trac.sagemath.org/ticket/33440 fixes the problem and is waiting for review.
Reply all
Reply to author
Forward
0 new messages