Ask Your Question
0

location of sage -python executable

asked 2011-06-22 15:28:32 +0100

Tim Fuller gravatar image

I wanted to know the path of the python interpreter that sage uses, so I executed

sage -python
Python 2.6.4 (r264:75706, Jun 20 2011, 12:34:18) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/tjfulle/Local/math/sage/darwin/local/bin/python'

Then, I navigate to /Users/tjfulle/Local/math/sage/darwin/local/bin to call the interpreter that sage uses directly:

./python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/tjfulle/Local/math/sage/darwin/local/bin/python'

The output from sys.executable is the same for each case, but clearly, the two interpreters are different, for sage -python, the interpreter is Python 2.6.4 and for /Users/tjfulle/Local/math/sage/darwin/local/bin/python the interpreter is Python 2.6.1.

Am I missing something? Which python interpreter is being used when I type sage -python?

When performing the same exercise on my redhat machine, when I execute /home/tjfulle/Local/math/sage/redhat/local/bin/python it returns

./python: error while loading shared libraries: libpython2.6.so.1.0: 
cannot open shared object file: No such file or directory

I'd like to use the python built in with sage, but call it directly bypassing the sage -python layer. Is this possible?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2011-06-22 15:37:34 +0100

Volker Braun gravatar image

Sage's version of Python (and many other programs) rely on Sage's shared libraries. You can set up the necessary environment with sage -sh and then call python directly.

edit flag offensive delete link more
1

answered 2011-06-22 15:47:05 +0100

Mike Hansen gravatar image

updated 2011-06-22 15:49:57 +0100

When you start the python executable, it looks for the libpython2.6.so.1.0 shared library which contains the "interesting" parts of the Python language. When you run /home/tjfulle/Local/math/sage/redhat/local/bin/python as opposed to sage -python, the Python executable picks up the system version of libpython2.6.so.1.0. For example, here is the output of ldd /opt/sage/local/bin/python on my machine:

...
libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00007f32d5c19000)
...

See how it is using the "system" libpython2.6.so.1.0. When you run sage -python, it runs that same copy of Python in a "Sage environment" which primarily changes the paths where the shared libraries get looked up. If I do sage -sh and then do ldd /opt/sage/local/bin/python, I get

...
libpython2.6.so.1.0 => /opt/sage/local/lib/libpython2.6.so.1.0 (0x00007f499c1d8000)
...

You are seeing the error on your RedHat machine since it doesn't have a libpython2.6 shared library to load.

If you want to use Sage's version of Python directly, then you have to have the appropriate enviroment variables set up so that it can find the needed libraries. The easiest way to do this is to run sage -sh to go into a shell with the environment variables set up or to source $SAGE_ROOT/local/bin/sage-env to set the variables directly in the current shell.

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

Stats

Asked: 2011-06-22 15:28:32 +0100

Seen: 2,081 times

Last updated: Jun 22 '11