ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 01 Oct 2020 03:08:30 -0500EOL error in Sage-9.1https://ask.sagemath.org/question/53682/eol-error-in-sage-91/I want to modify a Python package for solving 'Quasi normal modes' using SageMath if possible, I want the below error to be fixed.
?qnm.modes_cache
grav_220 = qnm.modes_cache(s=-2, l=2, m=2, n=0)
omega, A, C = grav_220(a=0.68)
print('ω={}, A={}'.format(omega, A))
print('C={}''.format(C))
I get the error for the second input as
File "<ipython-input-13-1f77b2f8a4ef>", line 4
print('C={}''.format(C))
^
SyntaxError: EOL while scanning string literalsaxadThu, 01 Oct 2020 03:08:30 -0500https://ask.sagemath.org/question/53682/Install Docker image with Python2https://ask.sagemath.org/question/53488/install-docker-image-with-python2/I am trying to install a local Docker image of CoCalc, however, I'd like to keep using Sage-8.9 with Python2. Following the github instructions, I run
docker run --name=cocalc -d -v ~/cocalc:/projects -p 443:443 sagemathinc/cocalc
which results in Sage-9.1, so all my code stops working. How do I switch to Sage-8.9 with docker?
pgalashinFri, 18 Sep 2020 03:52:53 -0500https://ask.sagemath.org/question/53488/sagemath files opening as python fileshttps://ask.sagemath.org/question/52867/sagemath-files-opening-as-python-files/For some reason my .ipynb files are now all opening as python3 files so things don't work, and I can't seem to change back.cybervigilanteWed, 05 Aug 2020 04:14:14 -0500https://ask.sagemath.org/question/52867/using computation results from before switch to Python3 (sage9)https://ask.sagemath.org/question/52613/using-computation-results-from-before-switch-to-python3-sage9/I have lots of precomputed data computed by sage8.9 and before that I rely on. The reason I save that data is that it took a lot of computation time to obtain it. The data is saved as .sobj-files.
Suddenly I get "invalid pickle data"-errors when trying to load some of that data with the new version of sage. (I'm using sage9.1 now.) I am therefore unable to do computations on top of the precomputed data.
I strongly suspect that this issue is due to basing sage9.x on Python3.
How do I convert the data so that I can use it in the new version of sage?
Help is greatly appreciated. oloidWed, 22 Jul 2020 06:38:33 -0500https://ask.sagemath.org/question/52613/Some code gives error in sagemath 9 but OK in 8.9https://ask.sagemath.org/question/50204/some-code-gives-error-in-sagemath-9-but-ok-in-89/After I upgraded to sagemath 9.0 some of the code that used to work now gives error. The code was used to obtain an estimate of size of expression.
>sage --version
SageMath version 9.0, Release Date: 2020-01-01
>which sage
/bin/sage
It looks like sagemath 9 now uses python 3.0 while 8.9 used python 2 (since I had to change all my print statements to use () to make them work.
Here is an example of function that now gives an error. This is in file, say `bug_sage.py`
#!/usr/bin/env sage
from sage.all import *
def tree(expr):
if expr.operator() is None:
return expr
else:
return [expr.operator()]+map(tree, expr.operands())
var('x')
tree(x*e**((x*log(x) + 1)/log(x)))
Now from command line at Linux, I type `sage ./bug_sage.py` and it gives the error
Traceback (most recent call last):
File "./bug_sage.py", line 12, in <module>
print (tree(x*e**((x*log(x) + 1)/log(x))))
File "./bug_sage.py", line 9, in tree
return [expr.operator()]+map(tree, expr.operands())
TypeError: can only concatenate list (not "map") to list
In 8.9, no error is generated.
It looks like this is due to change in Python itself? This function is meant to generate list of all operands in expression in order to estimate the size of the expression. It is later used as follows
len(flatten(tree(anti)))
Any idea how to fix it? Or do you suggest better way to obtain size of expression (called leaf count in other CAS systems).
NasserMon, 09 Mar 2020 15:52:26 -0500https://ask.sagemath.org/question/50204/SageMath-9.0.app fails to start on macOS 10.14.6https://ask.sagemath.org/question/49455/sagemath-90app-fails-to-start-on-macos-10146/Happy New Year
Hi,
SageMath-9.0.app fails to start on macOS 10.14.6 :
- the file:///Applications/SageMath-9.0.app/Contents/Resources/loading-page.html
appears on Firefox
- the log file says :
/Applications/SageMath-9.0.app/Contents/Resources/sage/src/bin/sage:
line 617: exec: python3: not found
However, everything works fine in a term window
- /Applications/SageMath-9.0.app/Contents/Resources/sage/sage --notebook=jupyter
- copy and paste one of these URLs:
http://localhost:8888/?token=688ebf865543565eaab657179de84b86dcf188138140750a
Can anyone help ?
Thank youepimetheusWed, 08 Jan 2020 14:05:47 -0600https://ask.sagemath.org/question/49455/Problem importing Sage library in Python script on Windowshttps://ask.sagemath.org/question/49452/problem-importing-sage-library-in-python-script-on-windows/I have a script that is fully operational which uses Sage as a python library in my python script. It runs completely normal on MacOS. However, when I tried to transfer this to work, where we are on Windows, I cannot load Sage in my python script. I get a ModuleNotFoundError.
Some background on this. My MacOS setup was generated via miniconda, including the conda package install of sage. Really, I'm only using Sage for a nice python friendly interface to Maxima, where I can do some very complex symbolic matrix computations very quickly.
On Windows, I was using MSYS2. However, after reading that Sage does not support this whatsoever, I installed Cygwin. Everything, except Sage, is running fine on Cygwin. I installed Sage via the Windows installer.
What do I need to do with the installation to get my python script to find Sage?
As an aside, is there a reason why there is no conda package for Sage on Windows, only Linux and MacOS? Trying to install Sage on Windows has been an all day, 2 day nightmare, and it is still not working. The Windows installer works fine if you just want to use Sage completely standalone. But it seems completely incompatible for integration with other languages/tools. I even tried to self compile. It took ~5-6 hours, then I got an error that one of the packages, bleach, failed. When I looked at the log for that, it seems like there was a connection issue and the source could not be downloaded. This all seems like complete overkill for using Sage in a python script.mattbWed, 08 Jan 2020 12:52:08 -0600https://ask.sagemath.org/question/49452/Taylor expansion crashing (python3)https://ask.sagemath.org/question/48429/taylor-expansion-crashing-python3/I type the following in the sage terminal :
f = (x+1)**(0.1)+exp(x)
f.taylor(x,0,3)
That causes me quite a crash I do not understand.
I tried with some variations, like
f = x**(0.1)+exp(x)
f.taylor(x,0,3)
or
f = (x+1)**(0.1)+exp(x)
f.taylor(x,0,2)
Both are working well.
EDIT :
This one
g = 3*(x+1)**(1/10)+exp(x)
g.taylor(x,0,3)
- works well in the sage terminal
- crashes when it is in a file "attach"ed to the sage terminal.
I guess it is due to the Sage's preparser.
Any idea ? Why does the Taylor expansion of that particular function crashes from order 3 ?
If it is important, I'm using a home-compiled version of Sage with python3 :
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.9, Release Date: 2019-09-29 │
│ Using Python 3.7.3. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
Here is the trace :
┌─────────────────────────────────┐
│ SageMath version 8.9, Release Date: 2019-09-29 │
│ Using Python 3.7.3. Type "help()" for help. │
└─────────────────────────────────┘
sage: f = (x+1)**(0.1)+exp(x)
sage: f.taylor(x,0,3)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
707 try:
--> 708 self._name = parent._create(value, name=name)
709 except (TypeError, RuntimeError, ValueError) as x:
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _create(self, value, name)
605 else:
--> 606 self.set(name, value)
607 except RuntimeError as error:
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in set(self, var, value)
514 cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 515 self.eval(cmd)
516
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _eval_line(self, line, locals, reformat, **kwds)
460 if statement:
--> 461 maxima_eval("#$%s$" % statement)
462 if not reformat:
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:7793)()
805 lispargs = EclObject(list(args))
--> 806 return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
807
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:5455)()
377 s = si_coerce_to_base_string(ecl_values(1))
--> 378 raise RuntimeError("ECL says: {}".format(
379 char_to_str(ecl_base_string_pointer_safe(s))))
RuntimeError: ECL says: In function GCD, the value of the first argument is
0.91
which is not of the expected type INTEGER
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-2-ed48eb8006d1> in <module>()
----> 1 f.taylor(x,Integer(0),Integer(3))
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.taylor (build/cythonized/sage/symbolic/expression.cpp:27942)()
4581 except Exception:
4582 raise NotImplementedError("Wrong arguments passed to taylor. See taylor? for more details.")
-> 4583 l = self._maxima_().taylor(B)
4584 return self.parent()(l)
4585
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, *args, **kwds)
668
669 def __call__(self, *args, **kwds):
--> 670 return self._obj.parent().function_call(self._name, [self._obj] + list(args), kwds)
671
672 def help(self):
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in function_call(self, function, args, kwds)
589 [s.name() for s in args],
590 ['%s=%s'%(key,value.name()) for key, value in kwds.items()])
--> 591 return self.new(s)
592
593 def _function_call_string(self, function, args, kwds):
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in new(self, code)
358
359 def new(self, code):
--> 360 return self(code)
361
362 ###################################################################
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
286
287 if isinstance(x, string_types):
--> 288 return cls(self, x, name=name)
289 try:
290 # Special methods do not and should not have an option to
/home/moky/.Sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
708 self._name = parent._create(value, name=name)
709 except (TypeError, RuntimeError, ValueError) as x:
--> 710 raise TypeError(x)
711
712 def _latex_(self):
TypeError: ECL says: In function GCD, the value of the first argument is
0.91
which is not of the expected type INTEGERLaurentClaessensSat, 19 Oct 2019 09:22:27 -0500https://ask.sagemath.org/question/48429/Sage is not preparsing Python 3 underscored integershttps://ask.sagemath.org/question/47908/sage-is-not-preparsing-python-3-underscored-integers/Hello, Sage community!
With the upcoming migration of Sage from Python 2 to Python 3 (really soon, let us hope!), there are some testings I have been trying, and I have noticed that the "underscored integer literals", like "1_000_000" are not preparsed by Sage. For example,
preparse('1_000_000 + 3')
results in
'1_000_000 + Integer(3)'
However,
preparse('1000000 + 3')
returns
'Integer(1000000) + Integer(3)'
On the other hand, if I write
type(1_000_000 + 3)
the result is
<class 'sage.rings.integer.Integer'>
which is great, but
type(1_000_000 + 3_000)
instead gives me
<class 'int'>
Finally,
type(1000000 + 3000)
gives us
<class 'sage.rings.integer.Integer'>
I know one of the reasons for the `Integer` type was to allow divisions like `3/2` to return the float `1.5` even with Python 2, which would return (very disturbingly) `1`, in other case. However, Python 3 integers already do this. Besides what I mentioned above and this, I haven't found any other difference in behavior.
So I was wondering: Is there any disadvantage in Sage not being preparsing this type of literals?dsejasFri, 13 Sep 2019 15:41:47 -0500https://ask.sagemath.org/question/47908/sage-8.9 fails compilation in Ubuntu 18.04https://ask.sagemath.org/question/48112/sage-89-fails-compilation-in-ubuntu-1804/ Hello, Sage community!
I just downloaded the sage-8.9 source code. I tried to compile it with Python 3, but the process stops with an error when trying to install `matplotlib`. The problem seems to be related to the fact that the installer is looking for `libpng12`, which is no longer available at Ubuntu 18.04's repositories. I get the following error message:
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.16.1]
install_requires: yes [handled by setuptools]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: yes [version 2.9.1]
png: no [The C/C++ header for libpng (png.h) could not
be found. You may need to install the development
package.]
qhull: yes [pkg-config information for 'libqhull' could not
be found. Using local copy.]
[SOME EXTRA USELESS INFO HERE AND THEN...]
============================================================================
* The following required packages can not be built:
* png
* Try installing png with `apt-get install
* libpng12-dev` and pkg-config with `apt-get install
* pkg-config`
Is there something I can do in the meanwhile?
Thanks in advance!dsejasMon, 30 Sep 2019 20:03:25 -0500https://ask.sagemath.org/question/48112/Import sage in python3https://ask.sagemath.org/question/47465/import-sage-in-python3/ Hi,
I've just finished building sage from source with python3, and it works great! I'm just wondering why `from sage.all import *` doesn't work in my python3, although trying the same in the sage shell works, so I guess it has to be a matter of environment variables? What should I do to be able to import sage in python3 scripts without having to rely on a sage shell?
Best,
Florianarty-hlrMon, 12 Aug 2019 14:08:01 -0500https://ask.sagemath.org/question/47465/