Ask Your Question
1

Unable to use Macaulay2 interface of sage in .sage file

asked 2022-04-04 05:39:47 +0100

Dharm gravatar image

updated 2022-04-04 11:30:33 +0100

I am doing some calculations in sage using Macaulay2 interface. While runing the Macaulay2 interface in .sage file, I am getting the following error:

NameError: name 'macaulay2' is not defined

For example, consider the following:

R = macaulay2.ring('QQ', '[x]');

I = macaulay2.ideal(x)

n = macaulay2.res(I)

print(n)

My commands are correct. In fact, these are working in jupyter notebook and in sage terminal.

Can anyone help me in this regard?

edit retag flag offensive close merge delete

Comments

Please provide the commands one can run in a fresh Sage session to reproduce the issue.

slelievre gravatar imageslelievre ( 2022-04-04 09:39:48 +0100 )edit

I have updated the question.

Dharm gravatar imageDharm ( 2022-04-04 11:30:49 +0100 )edit

How do you evaluate/load the .sage script ? Which command ?

tmonteil gravatar imagetmonteil ( 2022-04-04 12:31:51 +0100 )edit

The command I give is:

run "abc.sage"

where abc.sage is the file name. I am using SageMath 9.2 on ubuntu 16.04.

Dharm gravatar imageDharm ( 2022-04-04 16:10:36 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-04 16:30:17 +0100

tmonteil gravatar image

If you use run, then the .sage file is understood as an independent Python script, hence you should import the required modules, e.g.

from sage.interfaces.macaulay2 import macaulay2

Alternatively, you can use runfile (or %runfile) instead of run.

edit flag offensive delete link more

Comments

Thank you. Both of these are working for me.

Dharm gravatar imageDharm ( 2022-04-04 18:50:34 +0100 )edit

@Dharm -- Please accept this answer (click the "accept" button next to the answer) to mark the question as solved.

slelievre gravatar imageslelievre ( 2022-04-05 13:50:13 +0100 )edit

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: 2022-04-04 05:39:47 +0100

Seen: 232 times

Last updated: Apr 04 '22