Ask Your Question
2

Import sage in python3

asked 2019-08-12 21:08:01 +0100

arty-hlr gravatar image

Hi,

I've just finished building sage from source with python3, and it works great! I'm just wondering why from sage.all import * doesn't work in my python3, although trying the same in the sage shell works, so I guess it has to be a matter of environment variables? What should I do to be able to import sage in python3 scripts without having to rely on a sage shell?

Best,

Florian

edit retag flag offensive close merge delete

Comments

(Sort of) WorksForMe(TM):

charpent@p-202-021:~$ sage -python
Python 3.7.3 (default, Jul 10 2019, 14:13:36) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> x=var("x")
>>> integrate(arctan(x),x)
x*arctan(x) - 1/2*log(x^2 + 1)
>>> quit()

However:

charpent@p-202-021:~$ python3
Python 3.7.4 (default, Jul 11 2019, 10:43:21) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sage'
>>> quit()

You have to somehow tell to Python the place where to look for Sage...

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-08-13 11:05:57 +0100 )edit

The full sage build includes its own Python interpreter--it doesn't install the sage package in your system's Python (eventually there will be an option for this by way of #27824 but that's a ways away yet :(

Iguananaut gravatar imageIguananaut ( 2019-08-14 13:42:53 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-08-13 11:42:42 +0100

slelievre gravatar image

As @Emmanuel_Charpentier hints at in his comment, this requires using Sage's Python.

If you built from source, you can call Sage's Python with sage --python.

Or you could change your path so that Sage's Python is found first. Use with caution, as other apps / scripts / uses may rely on python calling the system Python.

Note that you can install SageMath using Conda; it will install for Python 3. With the corresponding Conda environment activated, python will be the Python 3 which has SageMath installed on top of it. In that Python, from sage.all import * will work.

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: 2019-08-12 21:08:01 +0100

Seen: 3,010 times

Last updated: Aug 13 '19