Opened 9 years ago

Closed 8 years ago

#15308 closed defect (fixed)

init.sage file is not read when starting the notebook

Reported by: John Palmieri Owned by:
Priority: critical Milestone: sage-duplicate/invalid/wontfix
Component: notebook Keywords:
Cc: Volker Braun, Punarbasu Purkayastha, Andrey Novoseltsev Merged in:
Authors: Reviewers: Karl-Dieter Crisman
Report Upstream: Completely fixed; Fix reported upstream Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


See This problem seems to have been introduced in #14523.

Change History (14)

comment:1 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:2 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:3 Changed 9 years ago by Robert John Barker

An example of output caused by this bug is:

Traceback (most recent call last): #The OrthogonalCurvilinearOutput?.sage file will output the coefficients and differential operators defined

File "", line 1, in <module>

File "/tmp/tmpPnuBJt/", line 7, in <module>


File "lazy_import.pyx", line 358, in sage.misc.lazy_import.LazyImport?.call (sage/misc/lazy_import.c:3000) File "/home/sagedev/sage/local/lib/python2.7/site-packages/sage/misc/", line 344, in attach

load(filename, globals(), attach=True)

File "/home/sagedev/sage/local/lib/python2.7/site-packages/sage/misc/", line 1769, in load

execfile(preparse_file_named(fpath), globals)

File "/home/sagedev/.sage/temp/ubuntu/18360/", line 18, in <module>


NameError?: name 'var' is not defined

comment:4 Changed 9 years ago by Volker Braun

Afaik attach doesn't work on the notebook.

Your problem seems to be that init.sage is evaluated before Sage is started. A workaround might be to use a .py file starting with from sage.all import *

comment:5 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:6 Changed 8 years ago by Karl-Dieter Crisman

Component: miscnotebook
Report Upstream: N/AReported upstream. Developers acknowledge bug.

Upstream at though I'm not sure if it's identical to the init.sage issue.

comment:7 Changed 8 years ago by Karl-Dieter Crisman

I appear to have a fix upstream; comments welcome there. Somehow the change in #14523 in the definition of attach from

    import preparser 
        for filename in files: 
        preparser.load(filename, globals(), attach=True) 


        ipy = get_ipython()
    except NameError:
        ipy = None
    global attached
    for filename in files:
        if ipy:
            code = load_wrap(filename, attach=True)
            load(filename, globals(), attach=True)

did this. Probably that should really be fixed in Sage, but I don't want to mess around with two fixes.

Can anyone think of why either adding that global (which one would think wouldn't clobber all globals, such as Integer?) or having the command-line code would be a problem? Really, neither one should in principle cause a problem. But it does.

comment:8 Changed 8 years ago by Karl-Dieter Crisman

Indeed, a little more testing shows that globals() is definitely not the usual Sage globals at that point - it is just the globals for that module, including the things that were imported like os and the builtins. E.g.

'{\'load\': <function load at 0x1054cc488>, \'load_attach_path\': <function load_attach_path at 0x110d99e60>, \'reload_attached_files_if_modified\': <function reload_attached_files_if_modified at 0x110d9f2a8>, ...
 \'__doc__\': \'\\nKeep track of attached files\\n\\nTESTS::\\n\\n    sage: attach(\\\'\\\')\\n    Traceback (most recent call last):\\n    ...\\n    ...
 \'load_wrap\': <function load_wrap at 0x1054cc500>, \'load_attach_mode\': <function load_attach_mode at 0x110d99de8>, 
\'__builtins__\': {\'bytearray\': <type \'bytearray\'>, \'IndexError\': <type \'exceptions.IndexError\'>, ...}, 
\'os\': <module \'os\' from \'/Users/.../sage/local/lib/python/os.pyc\'>, \'modified_file_iterator\': <function modified_file_iterator at 0x110d9f230>}'


comment:9 Changed 8 years ago by Karl-Dieter Crisman

From the Python doc:

Remember that at module level, globals and locals are the same dictionary.

But on the other hand nothing really changed. Except maybe that it was in a Cython file, and now is in a Python file?

comment:10 Changed 8 years ago by Karl-Dieter Crisman

Report Upstream: Reported upstream. Developers acknowledge bug.Completely fixed; Fix reported upstream

comment:11 Changed 8 years ago by Karl-Dieter Crisman

Cc: Punarbasu Purkayastha Andrey Novoseltsev added

This is 100% ready to go, just need a reviewer upstream!

comment:12 Changed 8 years ago by Karl-Dieter Crisman

Milestone: sage-6.4sage-duplicate/invalid/wontfix
Reviewers: Karl-Dieter Crisman
Status: newneeds_review

This was fixed and is now in a merged package.

comment:13 Changed 8 years ago by Karl-Dieter Crisman

Status: needs_reviewpositive_review

comment:14 Changed 8 years ago by Volker Braun

Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.