Running sage script from python script

121 views
Skip to first unread message

Aleksandra Pietrzkiewicz

unread,
Dec 29, 2021, 5:11:44 AM12/29/21
to sage-support
Hi, 
I have an issue with compatibility, I think. 
I want to call some functions from sage script (but saved as .py) from another python3 script. 
so my matrix.py is like: 

#!/usr/bin/sage 
from sage.all import *

def my_field(dim): 
   return GF(2**dim, 'a')
#and more here - like creating special matrixes

and I want to call it from python3 script (smth.py) like: 
import matrix.py
M = gen_matrix(my_field(4))


but I do always get some issues, like: ModuleNotFoundError or alike, because I start with:
python3 smth.py and_some_args.


Did someone ever had some similar issue? 
I'd appreciate some help.

Dima Pasechnik

unread,
Dec 29, 2021, 6:19:47 AM12/29/21
to sage-support
On Wed, Dec 29, 2021 at 10:11 AM Aleksandra Pietrzkiewicz
<aleksandr...@gmail.com> wrote:
>
> Hi,
> I have an issue with compatibility, I think.
> I want to call some functions from sage script (but saved as .py) from another python3 script.
> so my matrix.py is like:
>
> #!/usr/bin/sage
> from sage.all import *
>
> def my_field(dim):
> return GF(2**dim, 'a')
> #and more here - like creating special matrixes
>

This would be fine to run as ./matrix.py (assuming your Sage is indeed
/usr/bin/sage, else you need to replace
this with the correct path).

If you just want to import is as a Python module then you don't need
the 1st #! line at all.



> and I want to call it from python3 script (smth.py) like:
> import matrix.py
> M = gen_matrix(my_field(4))
>
>
> but I do always get some issues, like: ModuleNotFoundError or alike, because I start with:
> python3 smth.py and_some_args.

this most likely means that python3 does not know anything about Sage,
i.e. the latter has its own,
different, installation of Python3, which you can start as

sage --python

HTH
Dmitrii

>
>
> Did someone ever had some similar issue?
> I'd appreciate some help.
>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/3485945f-97d8-4a06-9955-3cee291b345en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages