Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I don't know whether this is the correct place to ask such a question, but I am dealing with this problem for a couple of days.

Take for example the script

What I do is: copy the script to a txt file and name it Then I go to my sage notebook and choose above the option 'gp'. In the first block I write

\r filename

where filename is the whole path of the file (so C:....\ and "evaluate" it. But then I get the error

* at top-level: read("/home/sage/.sa * ^--------------------

* read: error opening input file: `C:\Users...\'.

If you see me doing things wrongly please let me know it :-) I am working with sage 4.7.1


EDIT: I have changed the "source" of the problem

share|cite|improve this question
There is nothing wrong with asking such a question here. But, I think you would probably get better/quicker answers if you ask at There are several people there that know about most aspects of Sage. – Graphth Mar 18 '12 at 13:18
That was my first step :-) But no one replied (see the fourth last question). – Nadori Mar 18 '12 at 13:29
up vote 3 down vote accepted

Here is how to do this in a Sage worksheet. See this worksheet (login required). (Since this interface will eventually become the standard Sage Notebook, this answer will eventually be relevant for offline use. Also, cloud.sagemath didn't exist when you asked your question...)

  1. Upload your file to a project: use +New and paste in the URL

  2. Make a New Sage worksheet with first cell:

    %default_mode gp

and second cell

  1. The rest of your worksheet is a full GP worksheet, and the code in that file is available. (You can use %sage at the top of a cell to temporarily escape back to sage mode.)

  2. You can also directly click on and edit it (I just noticed there's no syntax highlighting for gp scripts, but I'll fix that soon), and the editor has themes, and also a vim/emacs mode if you need that.

enter image description here

-- William

share|cite|improve this answer

In do this:

  1. Create a project and a new Sage worksheet in the project.

  2. Paste in this line and press shift+enter:''))

  3. In another cell, type this to confirm that you've loaded the code.

  4. Use it -- type %gp at the start of a cell to use gp.

share|cite|improve this answer
That solves this concrete problem. But what if I want to use a script that I wrote? I mean when I copy and paste the gp code of tate_via_nets and evaluate it I get an infinite loop ... – Nadori Mar 18 '12 at 19:56
@user1286 Hi, the link does not work anymore. Is it possible for you to update the link? Thanks! – BlackAdder Jun 30 '14 at 4:58
I've made it so downloading from is now allowed so that link works. I've updated the answer. – user1286 Oct 12 '14 at 0:25

Why does it not work if I copy and paste the code in Sage notebook? If I copy the code to a cell in Sage notebook and evaluate it, it just keeps running. The solution provided by user1286 is okay if I would not have to adjust the code and so on.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.