Ask Your Question


asked 2017-09-18 10:15:57 +0200

matpen gravatar image

I wrote a C++ library and the related python bindings, and I would like to make use of them from sage. But whatever I try, I cannot get sage to load the library. Here is what I tried:


export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"

However, when I try to import from a jupyter notebook:

import mylib.mymodule.mysubmodule

I get the error:

ImportError: /usr/lib/ undefined symbol: sgemv_thread_n

I only could find one reference (ticket 22006 on - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install libopenblas-dev did not work for me). Note that mylib does not depend in any way on BLAS.


export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/
sudo ldconfig

But the library cannot be found this way:

ImportError: cannot open shared object file: No such file or directory


export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/ /usr/lib/sagemath/local/lib/
sudo ln -s /opt/mylib/lib/ /usr/local/lib/

This results in the same import error as in SECOND ATTEMPT.


export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/ /lib/

Now the library finally got loaded, but it cannot find its dependencies.

ImportError: cannot open shared object file: No such file or directory


What is the proper way to make sage resolve a custom library and its dependencies? I understand that sage tries to isolate itself as much as possible from the system, and I have also read that there is some "magic" going on to adjust environment variables: this seems to cause the problem (1).


Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:

apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary

Note that everything works as expected when using the library from the system python console.

edit retag flag offensive close merge delete


What about the following scenario? (Written only with the hope of isolating the problem point.)

  • starting a terminal, typing in it

    sage -sh

    to start the sage shell, which sets all environment variables as needed, then

  • extending / setting the needed variables SAGE_PATH, and LD_LIBRARY_PATH as in one of the attempts,

  • starting sage in this terminal and testing

  • and / or starting jupyter from this terminal and testing.

dan_fulea gravatar imagedan_fulea ( 2017-09-18 21:25:11 +0200 )edit

@dan_fuela thank you, just tried, but that leads to the same results (either library not found, or libblas conflict)

matpen gravatar imagematpen ( 2017-09-18 22:31:22 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-09-29 12:45:44 +0200

Jeroen Demeyer gravatar image

I think the easiest solution is to install your library and bindings inside the Sage environment instead of in /opt/mylib. Run

sage --sh

which will drop you in a "Sage shell". Now, install your stuff in $SAGE_LOCAL. For an autotools project, this would be

./configure --prefix="$SAGE_LOCAL" && make && make install

For a Python project, plain pip will work:

pip install PKGNAME
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-09-18 10:15:57 +0200

Seen: 538 times

Last updated: Sep 29 '17