ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 29 Sep 2017 12:45:44 +0200sage LD_LIBRARY_PATHhttps://ask.sagemath.org/question/38842/sage-ld_library_path/ 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:
1) FIRST ATTEMPT
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/libblas.so.3: undefined symbol: sgemv_thread_n
I only could find one reference (ticket 22006 on trac.sagemath.org - 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.
2) SECOND ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
But the library cannot be found this way:
ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
3) THIRD ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
This results in the same import error as in SECOND ATTEMPT.
4) FOURTH ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
Now the library finally got loaded, but it cannot find its dependencies.
ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
THE QUESTION
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).
ADDITIONAL INFO
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.Mon, 18 Sep 2017 10:15:57 +0200https://ask.sagemath.org/question/38842/sage-ld_library_path/Comment by dan_fulea for <p>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:</p>
<p>1) FIRST ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"
</code></pre>
<p>However, when I try to import from a jupyter notebook:</p>
<pre><code>import mylib.mymodule.mysubmodule
</code></pre>
<p>I get the error:</p>
<pre><code>ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n
</code></pre>
<p>I only could find one reference (ticket 22006 on http://trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install <code>libopenblas-dev</code> did not work for me). Note that <code>mylib</code> does not depend in any way on BLAS.</p>
<p>2) SECOND ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
</code></pre>
<p>But the library cannot be found this way:</p>
<pre><code>ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
</code></pre>
<p>3) THIRD ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
</code></pre>
<p>This results in the same import error as in SECOND ATTEMPT.</p>
<p>4) FOURTH ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
</code></pre>
<p>Now the library finally got loaded, but it cannot find its dependencies.</p>
<pre><code>ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
</code></pre>
<p>THE QUESTION</p>
<p>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). </p>
<p>ADDITIONAL INFO</p>
<p>Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:</p>
<pre><code>apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary
</code></pre>
<p>Note that everything works as expected when using the library from the system python console.</p>
https://ask.sagemath.org/question/38842/sage-ld_library_path/?comment=38849#post-id-38849What 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.Mon, 18 Sep 2017 21:25:11 +0200https://ask.sagemath.org/question/38842/sage-ld_library_path/?comment=38849#post-id-38849Comment by matpen for <p>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:</p>
<p>1) FIRST ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"
</code></pre>
<p>However, when I try to import from a jupyter notebook:</p>
<pre><code>import mylib.mymodule.mysubmodule
</code></pre>
<p>I get the error:</p>
<pre><code>ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n
</code></pre>
<p>I only could find one reference (ticket 22006 on http://trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install <code>libopenblas-dev</code> did not work for me). Note that <code>mylib</code> does not depend in any way on BLAS.</p>
<p>2) SECOND ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
</code></pre>
<p>But the library cannot be found this way:</p>
<pre><code>ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
</code></pre>
<p>3) THIRD ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
</code></pre>
<p>This results in the same import error as in SECOND ATTEMPT.</p>
<p>4) FOURTH ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
</code></pre>
<p>Now the library finally got loaded, but it cannot find its dependencies.</p>
<pre><code>ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
</code></pre>
<p>THE QUESTION</p>
<p>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). </p>
<p>ADDITIONAL INFO</p>
<p>Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:</p>
<pre><code>apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary
</code></pre>
<p>Note that everything works as expected when using the library from the system python console.</p>
https://ask.sagemath.org/question/38842/sage-ld_library_path/?comment=38850#post-id-38850@dan_fuela thank you, just tried, but that leads to the same results (either library not found, or libblas conflict)Mon, 18 Sep 2017 22:31:22 +0200https://ask.sagemath.org/question/38842/sage-ld_library_path/?comment=38850#post-id-38850Answer by Jeroen Demeyer for <p>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:</p>
<p>1) FIRST ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"
</code></pre>
<p>However, when I try to import from a jupyter notebook:</p>
<pre><code>import mylib.mymodule.mysubmodule
</code></pre>
<p>I get the error:</p>
<pre><code>ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n
</code></pre>
<p>I only could find one reference (ticket 22006 on http://trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install <code>libopenblas-dev</code> did not work for me). Note that <code>mylib</code> does not depend in any way on BLAS.</p>
<p>2) SECOND ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
</code></pre>
<p>But the library cannot be found this way:</p>
<pre><code>ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
</code></pre>
<p>3) THIRD ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
</code></pre>
<p>This results in the same import error as in SECOND ATTEMPT.</p>
<p>4) FOURTH ATTEMPT</p>
<pre><code>export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
</code></pre>
<p>Now the library finally got loaded, but it cannot find its dependencies.</p>
<pre><code>ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
</code></pre>
<p>THE QUESTION</p>
<p>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). </p>
<p>ADDITIONAL INFO</p>
<p>Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:</p>
<pre><code>apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary
</code></pre>
<p>Note that everything works as expected when using the library from the system python console.</p>
https://ask.sagemath.org/question/38842/sage-ld_library_path/?answer=39001#post-id-39001I 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 PKGNAMEFri, 29 Sep 2017 12:45:44 +0200https://ask.sagemath.org/question/38842/sage-ld_library_path/?answer=39001#post-id-39001