ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 19 Jan 2020 17:20:47 +0100- Sage is not updating modules imported by an attached filehttps://ask.sagemath.org/question/9221/sage-is-not-updating-modules-imported-by-an-attached-file/My file structure looks like:
<pre>
project/
__init__.py
project.py
bounds.py
</pre>
project.py looks approximately like:
<pre>
import sys
import os
import bounds
def myfunction(g):
if has_bound(g):
...
def has_bound(g):
lbound = 1
for name, obj in inspect.getmembers(bounds, inspect.isclass):
if obj.__module__ == 'bounds':
new_bound = obj.bound(g)
if new_bound > lbound:
lbound = new_bound
return lbound
</pre>
bounds.py:
<pre>
import abc
class BoundBase(object):
@staticmethod
@abc.abstractmethod
def bound(g):
return
class SpecificBound(LowerBoundBase):
@staticmethod
def bound(g):
return 5
</pre>
Now, I start a Sage session in the Terminal and do <code>attach project.py</code>. I can even make changes in project.py and see the results immediately in Sage. The problem is that if I change something in bounds.py, Sage won't pick up on the changes. I've tried combinations of reset(), detach(), attach(), load(), but the only thing that works is quitting Sage completely and restarting it. There must be a better way!patronicsThu, 09 Aug 2012 16:18:57 +0200https://ask.sagemath.org/question/9221/
- Problem with %attach for SageMath 9.0 on Windows 10 with .spyx fileshttps://ask.sagemath.org/question/44176/problem-with-attach-for-sagemath-90-on-windows-10-with-spyx-files/> EDIT (01/02/2020) on version 9.0.
Consider a source code reduced to the following line:
# %attach SAGE/AttachTest.spyx
When I attach it the first time, it is OK, but if I **save again** the source code, there is the following problem (which appears from version 8.3 or less). How to fix this problem?
Note that this problem is specific to .spyx files, as everything works well for .sage files.
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.0, Release Date: 2020-01-01 │
│ Using Python 3.7.3. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: %attach SAGE/AttachTest.spyx
Compiling ./SAGE/AttachTest.spyx...
sage: 0 [main] python3.7 1214 child_info_fork::abort: unable to map \??\C:\Users\SÃ©bastien Palcoux\.sage\temp\LAPTOP-7O5QV19T\1192\spyx\_home_sage_SAGE_AttachTest_spyx\_home_sage_SAGE_A
ttachTest_spyx_0.dll (using C:\Users\SÃ©bastien Palcoux\.sage\temp\LAPTOP-7O5QV19T\1192\spyx\_home_sage_SAGE_AttachTest_spyx\_home_sage_SAGE_AttachTest_spyx_0.dll), Win32 error 126
### reloading attached file AttachTest.spyx modified at 05:48:32 ###
Compiling /home/sage/SAGE/AttachTest.spyx...
---------------------------------------------------------------------------
BlockingIOError Traceback (most recent call last)
/opt/sagemath-9.0/local/lib/python3.7/site-packages/pkgconfig/pkgconfig.py in _wrapper(*args, **kwargs)
59 try:
---> 60 return func(*args, **kwargs)
61 except OSError as e:
/opt/sagemath-9.0/local/lib/python3.7/site-packages/pkgconfig/pkgconfig.py in _query(package, *options)
69 cmd = '{0} {1} {2}'.format(pkg_config_exe, ' '.join(options), package)
---> 70 proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
71 out, err = proc.communicate()
/opt/sagemath-9.0/local/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
774 errread, errwrite,
--> 775 restore_signals, start_new_session)
776 except:
/opt/sagemath-9.0/local/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1452 errpipe_read, errpipe_write,
-> 1453 restore_signals, start_new_session, preexec_fn)
1454 self._child_created = True
BlockingIOError: [Errno 11] Resource temporarily unavailable
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-2-7b41dee30a81> in <module>()
----> 1 sage.repl.load.load(sage.repl.load.base64.b64decode("L2hvbWUvc2FnZS9TQUdFL0F0dGFjaFRlc3Quc3B5eA=="),globals(),True)
/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/repl/load.py in load(filename, globals, attach)
274 if attach:
275 add_attached_file(fpath)
--> 276 exec(load_cython(fpath), globals)
277 elif ext == '.f' or ext == '.f90':
278 from sage.misc.inline_fortran import fortran
/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/repl/load.py in load_cython(name)
65 """
66 from sage.misc.cython import cython
---> 67 mod, dir = cython(name, compile_message=True, use_cache=True)
68 import sys
69 sys.path.append(dir)
/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/misc/cython.py in cython(filename, verbose, compile_message, use_cache, create_local_c_file, annotate, sage_namespace, create_local_so_file)
324 try:
325 ext, = cythonize([ext],
--> 326 aliases=cython_aliases(),
327 include_path=includes,
328 compiler_directives=directives,
/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/env.py in cython_aliases()
392 for lib in ['fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular']:
393 var = lib.upper().replace("-", "") + "_"
--> 394 aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split()
395 pc = pkgconfig.parse(lib)
396 # INCDIR should be redundant because the -I options are also
/opt/sagemath-9.0/local/lib/python3.7/site-packages/pkgconfig/pkgconfig.py in cflags(package)
106 If ``pkg-config`` not on path, raises ``EnvironmentError``.
107 """
--> 108 return _query(package, '--cflags')
109
110
/opt/sagemath-9.0/local/lib/python3.7/site-packages/pkgconfig/pkgconfig.py in _wrapper(*args, **kwargs)
60 return func(*args, **kwargs)
61 except OSError as e:
---> 62 raise EnvironmentError("pkg-config is probably not installed. Could not run pkg-config: %r"%e)
63 return _wrapper
64
OSError: pkg-config is probably not installed. Could not run pkg-config: BlockingIOError(11, 'Resource temporarily unavailable')
sage:Sébastien PalcouxSat, 03 Nov 2018 20:27:46 +0100https://ask.sagemath.org/question/44176/
- Automatically attach file on starting shell?https://ask.sagemath.org/question/49607/automatically-attach-file-on-starting-shell/Is there a way to run sage from command line and have sage automatically run a command (such as attaching a file)? I do not want to put the attach command in the init.sage file, because I want sage to only attach my code when I am working on my project, not for general use.
Perhaps another way of thinking about is how can I run a sage script, and have it exit into an interactive shell? Then I would be able to run sage mycode.sage, and have the desired behavior.
Thank you.hwong557Sun, 19 Jan 2020 17:20:47 +0100https://ask.sagemath.org/question/49607/
- How to attach a simple Sage script in a Sage Jupyter notebookhttps://ask.sagemath.org/question/43964/how-to-attach-a-simple-sage-script-in-a-sage-jupyter-notebook/**My two PCs' configurations:** Windows 8.1, Windows 10
**Sage version:** SageMath 8.3, windows installer 0.4
github.com/sagemath/sage-windows/releases
I want to use a Sage script in a Sage Jupyter Notebook (Jupyter with Sage as a kernel).
I have tried the following procedure:
1. I put a Sage code (definition of a function) in text file named Script.sage.
2. In a Jupyter notebook I tried command attach('Script.Sage')
3. I got a usage error:
UsageError: Invalid GUI request 'sage', valid ones are:[None, 'widget', 'qt5', 'qt', 'nbagg', 'osx', 'gtk', 'qt4', 'gtk3', 'notebook', 'tk', 'ipympl', 'inline', 'asyncio', 'wx']
Some advice about where is a problem? What to do?
Or is there another procedure how to use a Sage code written in separate files in a Jupyter notebook?
JozefTue, 16 Oct 2018 14:31:13 +0200https://ask.sagemath.org/question/43964/
- Using sagemath on windows 10 : impossible to attach filehttps://ask.sagemath.org/question/42870/using-sagemath-on-windows-10-impossible-to-attach-file/Hi! I've installed sagemath on windows 10 and I'm going crazy. The problem it seems to be that all the program is runing in some kind of temporal directory . I leave here some feedback from my console:
sage: load_attach_path()
['.']
If I change the path,
sage: load_attach_path('C:\Users\Javier\Desktop\current\height1')
sage: load_attach_path()
['.', 'C:\\Users\\Javier\\Desktop\\current\\height1']
So we can confirm the new path was added. Inside the folder height1 I have a file "'heigth1.sage". Let's try to attach it:
sage: attach("height1.sage")
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-4-cb4dd36405f2> in <module>()
----> 1 sage.repl.load.load(sage.repl.load.base64.b64decode("aGVpZ2h0MS5zYWdl"),globals(),True)
/opt/sagemath-8.2/local/lib/python2.7/site-packages/sage/repl/load.py in load(filename, globals, attach)
252 # See Trac 11812.
253 if attach:
--> 254 add_attached_file(fpath)
255 with open(preparse_file_named(fpath)) as f:
256 code = compile(f.read(), preparse_file_named(fpath), 'exec')
/opt/sagemath-8.2/local/lib/python2.7/site-packages/sage/repl/attach.py in add_attached_file(filename)
376 sage.repl.inputhook.install()
377 fpath = os.path.abspath(filename)
--> 378 attached[fpath] = os.path.getmtime(fpath)
379
380
/opt/sagemath-8.2/local/lib/python2.7/genericpath.py in getmtime(filename)
60 def getmtime(filename):
61 """Return the last modification time of a file, reported by os.stat()."""
---> 62 return os.stat(filename).st_mtime
63
64
OSError: [Errno 2] No such file or directory: '/home/Javier/C:\\Users\\Javier\\Desktop\\current\\height1/height1.sage'
----------
Recall the Error **No such file or directory: '/home/Javier/C:\\Users\\Javier\\Desktop\\current\\height1/height1.sage'**. What ?? Please, help me ! I will appreciate your feedback very much!JavidlgMon, 09 Jul 2018 17:26:08 +0200https://ask.sagemath.org/question/42870/
- Import Sage Worksheetshttps://ask.sagemath.org/question/41924/import-sage-worksheets/ Hello, I'm looking to be able to modulate my code in the Sage Math cloud. I've done some research on the topic and it seems that one could use the `attach` syntax to bring in the methods from another worksheet. Unfortunately I get the following error when I try to attach the sagews 'test' which is in the same folder as the worksheet I'm working in.
`File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 3443, in attach
raise IOError('did not find file %r to attach' % fname)
IOError: did not find file 'test' to attach`
Can anyone help me with this issue?
Thanks,
Adam
ajmullinsMon, 09 Apr 2018 02:24:28 +0200https://ask.sagemath.org/question/41924/
- Import just one function from .sage filehttps://ask.sagemath.org/question/39906/import-just-one-function-from-sage-file/I have a `.sage` file that has a single function I want to import. If it were a `.py` file, I would obviously use `from temp import myfun`, but as far as I know, `.sage` files have to be imported with either `load('temp.sage')` or `attach('temp.sage')` (or preparsed, but this gets tiresome). Is there a way to import just one function from a `.sage` file?jaebondSat, 02 Dec 2017 07:21:59 +0100https://ask.sagemath.org/question/39906/
- Loading a module causes the __name__ == '__main__' block to executehttps://ask.sagemath.org/question/38164/loading-a-module-causes-the-__name__-__main__-block-to-execute/I have a module that can also be run from the command line:
def func()
print('Hello!')
if __name__ == '__main__':
func()
When I try to load it in Sage, the main block is executed:
sage: load('module.sage')
Hello!
sage:
The bigger problem is that the main block parses command line arguments and Sage aborts the load with an error because it didn't receive any command line arguments. Is there any way to handle this? I can preparse `module.sage` and import it as a Python module, but its so much easier to `attach('module.sage')` than having to `reload(module)` every time I change it when I'm editing.
jaebondSun, 02 Jul 2017 16:44:02 +0200https://ask.sagemath.org/question/38164/
- How to attach a .sage file in virtualboxhttps://ask.sagemath.org/question/38055/how-to-attach-a-sage-file-in-virtualbox/ I'm trying to set up a text editor which I can use to edit and run in the terminal however when I try to cd to that file (located at C:\Users\myusername\Desktop\filename.sage) the terminal returns 'no such file or directory". Would I have to move my file somewhere specific? TriedgeThu, 22 Jun 2017 13:50:38 +0200https://ask.sagemath.org/question/38055/
- problems with attach on Machttps://ask.sagemath.org/question/36294/problems-with-attach-on-mac/I am having problems with attaching a file to a notebook. At first Sage cannot find cython, when I removed the cython calls sage cannot find parallel. See the code fragments and error below.
The code works as written when contained in the notebook. Am I doing something wrong or is this a bug?
Thank you for your help.
Mike
The code is:
...
cython("""
import numpy as np
import scipy as sp
from scipy import linalg
cimport numpy as np
cdef extern from "math.h":
float cosf(float theta)
float sinf(float theta)
def shape_calc_cy(Omega_array_stuff):
Omega_array_pt = Omega_array_stuff[0]
rf_shape = Omega_array_stuff[1]
t_step = Omega_array_stuff[2]
phi_p = Omega_array_stuff[3]
def pulse(Omega_0, omega_nut, t_p, phi_p):
Brot = np.matrix([[0,-Omega_0,omega_nut*sinf(phi_p)],[Omega_0,0,-omega_nut*cosf(phi_p)],[-omega_nut*sinf(phi_p),omega_nut*cosf(phi_p),0]],dtype = np.complex128)
return sp.linalg.expm(np.dot(Brot,t_p))
MPs = np.array([0,0,1],dtype = np.complexfloating)
for s in range(len(rf_shape)):
tmp = MPs
MPs = np.dot(pulse(Omega_array_pt, rf_shape[s], t_step, phi_p[s]),tmp)
return MPs
""")
...
The error is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_5.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfb3JpX2N5dGhvbi5zYWdlIikgIyBBdHRhY2ggbXkgQmxvY2ggcm91dGluZXMKYXR0YWNoZWRfZmlsZXMoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpcqrA7g/___code___.py", line 3, in <module>
attach ("/Users/michael/MHF_Bloch_n_Plot_ori_cython.sage") # Attach my Bloch routines
File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007)
File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach
load(filename, globals(), attach=True)
File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load
exec(code, globals)
File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_ori_cython.sagemdLt2C.py", line 193, in <module>
cython("""
NameError: name 'cython' is not define
The parallel code:
import multiprocessing
@parallel('fork', ncpus = (multiprocessing.cpu_count()))
def shape_calc(Omega_array_stuff):
return shape_calc_cy(Omega_array_stuff)
The parallel error is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_7.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfbm9fY3l0aG9uLnNhZ2UiKSAjIEF0dGFjaCBteSBCbG9jaCByb3V0aW5lcwphdHRhY2hlZF9maWxlcygp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpuKkIzm/___code___.py", line 3, in <module>
attach ("/Users/michael/MHF_Bloch_n_Plot_no_cython.sage") # Attach my Bloch routines
File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007)
File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach
load(filename, globals(), attach=True)
File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load
exec(code, globals)
File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_no_cython.sagesTGITt.py", line 216, in <module>
@parallel('fork', ncpus = (multiprocessing.cpu_count()))
NameError: name 'parallel' is not definedmhfreySun, 15 Jan 2017 02:10:09 +0100https://ask.sagemath.org/question/36294/
- Error on %attach for import __future__https://ask.sagemath.org/question/33946/error-on-attach-for-import-__future__/Hi,
using sagemath version 7.0 and 7.2, I tried to attach a file with %attach file.sage. The first line in the file is
from __future__ import division
which results in
sage: %attach file.sage
File "/home/user/.sage/temp/host/25397/file.sageTVxNnD.py", line 6
from __future__ import division
SyntaxError: from __future__ imports must occur at the beginning of the file
The error message is modified to hide user/host/... info
There is a older question on ask.sagemath /question/9071/future-import-fails-in-loading-external-cython-file/ which is addressing the same problem from 2012 on SageMath version 5.0 but there is no answer. I'm baffled that the error occurs in line 6 since the import statement is in the first line in the attached file.
Any ideas how to fix this?
temp_userTue, 28 Jun 2016 10:52:31 +0200https://ask.sagemath.org/question/33946/
- Differences between load and attachhttps://ask.sagemath.org/question/27012/differences-between-load-and-attach/Is the automatic reload of modified files the only difference between 'load' and 'attach'?
In such case, if there is not a slowdown in the 'attach' performance, should not be always 'attach' preferred over 'load'?franpenaWed, 03 Jun 2015 18:18:02 +0200https://ask.sagemath.org/question/27012/
- Attaching files in notebook does not update contentshttps://ask.sagemath.org/question/25611/attaching-files-in-notebook-does-not-update-contents/ Hello, I am running Sage 6.4.1. Using the notebook interface, attaching files does not work as the files contents are not reloaded automatically. It just shows me the previous variable values.
echo "x=2" > foo.py
attach foo.py
x
2
echo "x=4" > foo.py
x
2
As you can see the value of x isn't updated to 4. I can confirm that attach works as intended on the terminal, just the notebook interface is broken.NahsiNTue, 27 Jan 2015 04:30:02 +0100https://ask.sagemath.org/question/25611/
- Attaching files in notebook has not worked since 5.10https://ask.sagemath.org/question/24222/attaching-files-in-notebook-has-not-worked-since-510/ This has been reported in http://trac.sagemath.org/ticket/15308. But it doesn't look like fixing it is a very high priority for anyone that knows what they are doing - unfortunately I don't have a clue.
There is a comment that a workaround might be:
"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 *"
Can anyone help with telling me how to make use of this suggestion?BobBSun, 21 Sep 2014 07:15:46 +0200https://ask.sagemath.org/question/24222/
- Load .sage file into sage with VirtualBox Windows 8https://ask.sagemath.org/question/10745/load-sage-file-into-sage-with-virtualbox-windows-8/Hello there
I have problems to load a sage file into VirtualBox using Shared Folder. I have created a shared folder with volume name Newfolder and it's in /media/sf_Newfolder with files dghv.sage from https://github.com/coron/fhe inside of it. I tried to follow http://wiki.sagemath.org/SageAppliance with attach command but it showed error. In the github it said to load the sage file, so i use cd command cd /root/media/sf_Newfolder and load "dghv.sage" but it doesn't work and syntax error in it.
Can you help me?
ThanksihsanhaikalzSun, 17 Nov 2013 15:14:04 +0100https://ask.sagemath.org/question/10745/
- %attach misc.sage; a bug?https://ask.sagemath.org/question/10685/attach-miscsage-a-bug/Hi!
I'm running sage 5.11 on linux. I have a file called `misc.sage` which `%attach` seems to not like very much. The problem seems to be the filename, since even an empty file or just a print statement in it produce the same reaction. Is this a bug? Is this present in 5.12 too?
sage: %attach misc.sage [2/708]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-22-239b268dc29e> in <module>()
----> 1 get_ipython().magic(u'attach misc.sage')
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
2134 magic_name, _, magic_arg_s = arg_s.partition(' ')
2135 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2136 return self.run_line_magic(magic_name, magic_arg_s)
2137
2138 #-------------------------------------------------------------------------
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
2060 args.append(sys._getframe(stack_depth).f_locals)
2061 with self.builtin_trap:
-> 2062 result = fn(*args)
2063 return result
2064
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/sage/misc/sage_extension.pyc in attach(self, s)
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
189 # but it's overkill for just that one bit of state.
190 def magic_deco(arg):
--> 191 call = lambda f, *a, **k: f(*a, **k)
192
193 if callable(arg):
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/sage/misc/sage_extension.pyc in attach(self, s)
118 """
119 from sage.misc.preparser import load_wrap
--> 120 return self.shell.ex(load_wrap(s, attach=True))
121
122 @line_magic
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in ex(self, cmd)
2378 """Execute a normal python statement in user namespace."""
2379 with self.builtin_trap:
-> 2380 exec cmd in self.user_global_ns, self.user_ns
2381
2382 def ev(self, expr):
<string> in <module>()
/home/fidbc/._sys/opt/sage-5.11/local/lib/python2.7/site-packages/sage/misc/preparser.pyc in load(filename, globals, attach)
1721 return
1722
-> 1723 filename = filename.strip()
1724
1725 if filename.lower().startswith(('http://', 'https://')):
AttributeError: 'module' object has no attribute 'strip'fidbcSat, 02 Nov 2013 14:40:59 +0100https://ask.sagemath.org/question/10685/
- Why did attach become stupid?https://ask.sagemath.org/question/10258/why-did-attach-become-stupid/Recently, the attach feature poses two problems.
1. It says that "attach" is deprecated and that we should use "%attach". Why?
2. The real problem: "attach" and "%attach" now create a huge amount of stupid files in the folder. Why? How to prevent this?
3. How could the Sage developers let such an annoying thing make it in a Sage release and, worse, not correct it in newer versions?
Thanks in advance!subshiftSun, 23 Jun 2013 14:42:07 +0200https://ask.sagemath.org/question/10258/
- Cleaning up after %attach in 5.7https://ask.sagemath.org/question/9878/cleaning-up-after-attach-in-57/In 5.7, when I attach a file, call it `foo.sage`, I get files called something like `foo.sageQ7xLla` and `foo.sageQ7xLla.py` created in the directory, plus a new pair every time `foo.sage` is altered. Obviously, this gets tiresome really quickly. Is there a way to get sage to create this files wherever it was doing it before (some tmp directory, I assume) or to clean up after itself on exit?csarTue, 05 Mar 2013 10:54:17 +0100https://ask.sagemath.org/question/9878/
- sagenb uploadhttps://ask.sagemath.org/question/9670/sagenb-upload/I'm using sagenb, and I would like to import data from one worksheet to another. Both are on the server. I'm guessing that I should use attach or load commands, but I don't know what path to give them, because the files are not on my computer but on the server.
Thanks in advancebolverkTue, 01 Jan 2013 04:15:48 +0100https://ask.sagemath.org/question/9670/
- Why can't I attach files?https://ask.sagemath.org/question/8815/why-cant-i-attach-files/Hi -
I recently installed Sage on my new Macbook (although I've used Sage before, on my old -- and sadly, recently stolen -- Macbook). I'm using the Sage notebook. (Details of my installation below.)
If I attach a file ("attach foo.sage"), it loads/runs the commands in that file, just like it's supposed to and used to. However, if I make any alteration to the attached file while the Sage notebook is still running, then when I return to the notebook and try to do anything, Sage freaks out.
By "freak out," I mean that if I try to do any computation, even one that doesn't involve the variables or functions in the attached file (e.g., "2+2"), I get a massive error message, which ends with "RuntimeError: maximum recursion depth exceeded in cmp". I've pasted more of the error message below. This behavior continues until I quit and restart that notebook. It seems that the contents of the attached file are irrelevant -- I've tried it with simple files that contain nothing but a single print command, or something basic like "a=5".
I did a little searching, and I turned up [this discussion](http://groups.google.com/group/sage-notebook/browse_thread/thread/f0004f475fb26b23) on the sage-notebook Google Group, where William Stein notes this behavior. So obviously somebody who knows something is aware of this. But that was all I could find anywhere, and I have no sense for whether there is a fix/workaround for this.
I briefly tested to see if this also happens when I use Sage from a terminal. I don't get the recursion error then. However, if I re-enter the "attach" command after I've altered the attached file, it appears to run through the commands in that file twice. (So, for instance, if the attached file includes "print 'Hello!'", it will do this twice.) I understand that the command line avoids the error, but I would really prefer to use the notebook if I can.
Any ideas? Please speak slowly and use small words (metaphorically). Thanks!
---
The error message starts with...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_14.py", line 10, in <module>
File "", line 1, in <module>
File "/private/var/folders/5h/c6x89ch91fjgr43q99g8wbjw0000gn/T/tmphXrluN/___code___.py", line 3, in <module>
sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("Ii9Vc2Vycy9Kb2huL0Rlc2t0b3AvU2FnZV9zY3JpcHRzL3Rlc3Rlci5zYWdlIg=="),globals(),True)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1644, in load
execfile(preparse_file_named(fpath), globals)
File "/Users/John/.sage/temp/C_K_Dexter_Haven.local/34442/_Users_John_Desktop_Sage_scripts_tester_sage_6.py", line 6, in <module>
Then, the latter 4 lines (starting with "sage.misc.preparser.load") are repeated 492 more times, with the only thing changing being the number following "scripts_tester_sage_" in the last line. Then, it ends with:
sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("Ii9Vc2Vycy9Kb2huL0Rlc2t0b3AvU2FnZV9zY3JpcHRzL3Rlc3Rlci5zYWdlIg=="),globals(),True)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1644, in load
execfile(preparse_file_named(fpath), globals)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/interpreter.py", line 385, in preparse_file_named
preparse_file_named_to_stream(name, out)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/interpreter.py", line 368, in preparse_file_named_to_stream
parsed = preparse_file(contents)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1240, in preparse_file
numeric_literals=not numeric_literals))
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1126, in preparse
L)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 151, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 273, in _subx
template = _compile_repl(template, pattern)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 253, in _compile_repl
p = _cache_repl.get(key)
RuntimeError: maximum recursion depth exceeded in cmp
Installation details:
I'm using OSX Lion 10.7.3, and I installed the app version of Sage 4.8 (Sage-4.8-OSX-64bit-10.6.app). (Yes, I know I'm using the 10.6 version on a computer running 10.7, but as far as I could figure out, that's the best solution that works right now.) Thanks to some of the helpful posts and responses here on ASKSAGE about installing Sage on Lion, after some initial bumps, it seems to be running well, with this one exception.jdcThu, 22 Mar 2012 15:48:05 +0100https://ask.sagemath.org/question/8815/
- Where is walk.py located after I attach walk.sage?https://ask.sagemath.org/question/8488/where-is-walkpy-located-after-i-attach-walksage/The sage tutorial [Loading and Attaching Sage files](http://www.sagemath.org/doc/tutorial/programming.html) states that if I create a file such as walk.sage containing:
print "Hello world"
print 2^4
and then load or attach it:
sage: attach 'walk.sage'
Hello world
16
I should get a walk.py file containing python code in the same directory as walk.sage. I can find no such file (I've even searched my the rest of my computer). Does anyone know where the file is?
rtrwalkerThu, 17 Nov 2011 19:33:17 +0100https://ask.sagemath.org/question/8488/
- Autocompletion of filenames in Sage notebookhttps://ask.sagemath.org/question/8287/autocompletion-of-filenames-in-sage-notebook/I'm working within a Sage notebook (not a terminal). The tab autocompletion for commands is lovely, but is there something similar for filenames and folders when you're loading/attaching?
For example, if I want to attach the file myscripts/folder123/example456.sage (assuming that 'myscripts' is in my load_attach_path), I would type:
attach folder123/example456.sage
If I were to type only a portion of that path and hit tab, it doesn't autocomplete or give completions for the folder or filename; it either does nothing, indents, or (e.g., after the "e" in "example123") brings up a list of commands, without listing any filenames. Is there anything I can do to change this?
Disclaimer: I'm very new to all this, and pretty Unix-incompetent.jdcTue, 23 Aug 2011 11:50:32 +0200https://ask.sagemath.org/question/8287/
- How do instantiate a new class properly?https://ask.sagemath.org/question/8013/how-do-instantiate-a-new-class-properly/## Background ##
I have created a new class `FeynmanGraph` that is a subclass of `Graph`. It has some extra methods, and the module in which it lives also has some extra functions. The most important method for my purposes searches for possible colorings of the vertices that satisfy certain combinatorial criteria that have to do with spanning trees. (The details are not important here.)
The code works. I should mention that I'm editing `feynman.sage` in a text editor and attaching it to a sage session in a terminal. Once a I create an instance of the class via
> `G = FeynmanGraph(...)`
everything seems to work.
Now, I created a module in which I would like to define specific graphs, with specific labeling of the vertices and edges, as well as plot positioning information. Shouldn't I be able to import the module `feynman` and make definitions such as the following?
> `from feynman import *`<br>
> `def FatY(): # a particular graph`<br>
> `G = FeynmanGraph(...)`<br>
> `...`<br>
> `return G`
When I do this, the methods for `FeynmanGraph` raise all kinds of errors of the type where they don't recognize various functions, such as `max` or `partitions_set`.
## Question ##
How do I structure the modules and classes so that I can instantiate the class properly?Sammy BlackSat, 19 Mar 2011 03:23:26 +0100https://ask.sagemath.org/question/8013/
- how to organize multifile projecthttps://ask.sagemath.org/question/7980/how-to-organize-multifile-project/I am working on a project to do some computations for a specialized theory. Currently, we have several files that define different objects that have various dependencies on each other. Currently, I have a file named "attachall.sage" that looks like
attach "poly.sage"
attach "util2.sage"
attach "quasihomogeneous.sage"
attach "FJRW.sage"
attach "algebra.sage"
etc. Then when I want to do some computations, I do
sage: load attachall.sage
sage: #do stuff with the objects
It works fine, I guess, but doesn't seem particularly clean-- it seems like there should be a preferred way to do this. Should I use python's import? But then I would have to re-preparse every time I changed the source, and have potentially annoying bugs if someone forgot to re-preparse after changing a file. Or should I look into making a spkg? I don't really know a lot about that and I'd like to keep it simple.
Eventually we'd like to be able to share this code with other groups.
Does anyone have any thoughts?paragonWed, 02 Mar 2011 15:40:50 +0100https://ask.sagemath.org/question/7980/
- working directory for load/attachhttps://ask.sagemath.org/question/7822/working-directory-for-loadattach/Question
--------
Is there a command to change the current working directory inside *sage*, so that the *load* (or *attach*) command uses that directory as base?
Background
----------
I have the following file-directory-situtation:
- directory *project-base*
- file *blub.sage* (contains some useful functions)
- file *run.sage* (contains a **`load blub.sage`** command)
To start the project i call **`sage run.sage`** in the directory *project-base*. Everything works fine.
If I now want to run the project from any other directory with **`sage path/project-base/run.sage`**, I get the error message, that the file `tools.sage` is not found. The error message is kind of clear, because in *run.sage* the file is loaded without any directory specifications.
A similar problem occours, when you want to call *run.sage* from the browser-notebook-interface.
Is there any possibility to solve this problem (except using absolute paths everywhere (which is clearly not a satisfying solution) or changing the directory structure or using soft-links)?
Daniel KrennSat, 18 Dec 2010 10:33:10 +0100https://ask.sagemath.org/question/7822/