First time here? Check out the FAQ!

Ask Your Question
1

How to use libraries installed in for Python in Sage?

asked 8 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 8 years ago

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
Preview: (hide)
link
0

answered 7 years ago

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
>>> 
>>>
Preview: (hide)
link

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: 8 years ago

Seen: 2,543 times

Last updated: Jan 23 '16