ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 14 Aug 2019 06:42:53 -0500Import sage in python3http://ask.sagemath.org/question/47465/import-sage-in-python3/ 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,
FlorianMon, 12 Aug 2019 14:08:01 -0500http://ask.sagemath.org/question/47465/import-sage-in-python3/Comment by Iguananaut for <p>Hi,</p>
<p>I've just finished building sage from source with python3, and it works great! I'm just wondering why <code>from sage.all import *</code> 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?</p>
<p>Best,</p>
<p>Florian</p>
http://ask.sagemath.org/question/47465/import-sage-in-python3/?comment=47476#post-id-47476The 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](https://trac.sagemath.org/ticket/27824) but that's a ways away yet :(Wed, 14 Aug 2019 06:42:53 -0500http://ask.sagemath.org/question/47465/import-sage-in-python3/?comment=47476#post-id-47476Comment by Emmanuel Charpentier for <p>Hi,</p>
<p>I've just finished building sage from source with python3, and it works great! I'm just wondering why <code>from sage.all import *</code> 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?</p>
<p>Best,</p>
<p>Florian</p>
http://ask.sagemath.org/question/47465/import-sage-in-python3/?comment=47466#post-id-47466(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,Tue, 13 Aug 2019 04:05:57 -0500http://ask.sagemath.org/question/47465/import-sage-in-python3/?comment=47466#post-id-47466Answer by slelievre for <p>Hi,</p>
<p>I've just finished building sage from source with python3, and it works great! I'm just wondering why <code>from sage.all import *</code> 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?</p>
<p>Best,</p>
<p>Florian</p>
http://ask.sagemath.org/question/47465/import-sage-in-python3/?answer=47467#post-id-47467As @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.Tue, 13 Aug 2019 04:42:42 -0500http://ask.sagemath.org/question/47465/import-sage-in-python3/?answer=47467#post-id-47467