Ask Your Question
1

How to use libraries installed in for Python in Sage?

asked 2016-01-23 18:15:39 +0200

mavavilj gravatar image

I've installed some libraries to the 'normal' or 'system' Python on my computer.

However, Sage cannot see them.

How can I get Sage to use the libraries installed for Python? I'd prefer not to double install for Python and Sage separately.


I've noticed that Sage uses some Python from the Sage package. Which is clearly different than the one I'm using as "system Python". Is there a way to make these the same?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-23 23:49:15 +0200

tmonteil gravatar image

Indeed Sage has its own virtual environment, so it does not share Python libs with the system. Some Linux distributions try to so this but it requires quite some work.

If you want to experiment, you can try to symlink $SAGE_ROOT/local/lib/python22.7/site-packages/some_lib to the one of your system, but it does not awlays work. You can aslo add your system's Python lib directory to the Python path of Sage.

That said,i am not sure it is worth the effort for a single install, so unless you want to participate to some distribution packaging and share your experiments, double installing is currently usually preferable.

Note that you can install a Python library in Sage by typing from a terminal:

sage -pip install some_lib
edit flag offensive delete link more
0

answered 2017-08-22 15:54:06 +0200

I know this is not considered a clean and good workaround but at least works for me as issuing pip from sage is somehow seem broken for me and my tries for fixing it failed: just put this line on top of your script import sys; sys.path.append('/usr/local/lib/python2.7/site-packages') (or any other appropriate place your python 2 packages are installed), for example see:

~ sage --python
import Python 2.7.13 (default, Mar 25 2017, 16:37:39) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>> import sys; sys.path.append('/usr/local/lib/python2.7/site-packages')
>>> 
>>> import requests
>>> 
>>>
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

Stats

Asked: 2016-01-23 18:08:10 +0200

Seen: 2,151 times

Last updated: Jan 23 '16