Ask Your Question

Unable to use Macaulay2 interface of sage in .sage file

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

Dharm gravatar image

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

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)


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


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 +0200 )edit

I have updated the question.

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

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

tmonteil gravatar imagetmonteil ( 2022-04-04 12:31:51 +0200 )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 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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


Thank you. Both of these are working for me.

Dharm gravatar imageDharm ( 2022-04-04 18:50:34 +0200 )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 +0200 )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


Asked: 2022-04-04 05:39:47 +0200

Seen: 204 times

Last updated: Apr 04 '22