ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 May 2019 06:36:42 -0500using cplex as a solver in sage - import error undefined symbol: CPXsetlogfilehttp://ask.sagemath.org/question/46606/using-cplex-as-a-solver-in-sage-import-error-undefined-symbol-cpxsetlogfile/Hi,
Ubuntu 18.04; Installed cplex_studio129.linux-x86-64.bin and then Sage 8.7 from source.
I chose source to allow me to "make" Sage again after linking the necessary CPLEX files as described at the very bottom of the page here:
doc.sagemath.org/html/en/thematic_tutorials/linear_programming
i.e. from
/home/klara/sage-8.7/local/lib
`ln -s /opt/ibm/ILOG/CPLEX_Studio129/cplex/lib/x86-64_linux/static_pic/libcplex.a .`
and from:
/home/klara/sage-8.7/local/include
`ln -s /opt/ibm/ILOG/CPLEX_Studio129/cplex/include/ilcplex/cplex.h .`
and finally, also from:
/home/klara/sage-8.7/local/include
`ln -s /opt/ibm/ILOG/CPLEX_Studio129/cplex/include/ilcplex/cpxconst.h .`
But now I get the following import error when running:
sage: p = MixedIntegerLinearProgram(solver='CPLEX')
ImportError: /home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/numerical/backends/cplex_backend.so: undefined symbol: CPXsetlogfile
(By the way, after installing Sage but before linking and remaking I got the more basic import error:
`ImportError: No module named cplex_backend`)
Any hints as what to look into would be appreciated.
Thanks.
----------
Here is the Full Output of the error:
sage: p = MixedIntegerLinearProgram(solver='CPLEX')
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d320ed52392f> in <module>()
----> 1 p = MixedIntegerLinearProgram(solver='CPLEX')
/home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:3690)()
352 True
353 """
--> 354 return self.get_object()(*args, **kwds)
355
356 def __repr__(self):
/home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/numerical/mip.pyx in sage.numerical.mip.MixedIntegerLinearProgram.__init__ (build/cythonized/sage/numerical/mip.c:3931)()
449 self._first_variable_names = list(names)
450 from sage.numerical.backends.generic_backend import get_solver
--> 451 self._backend = get_solver(solver=solver,
452 constraint_generation=constraint_generation,
453 base_ring=base_ring)
/home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/numerical/backends/generic_backend.pyx in sage.numerical.backends.generic_backend.get_solver (build/cythonized/sage/numerical/backends/generic_backend.c:20060)()
1647 raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'CVXOPT', 'Gurobi', 'PPL', 'InteractiveLP', or None.")
1648
-> 1649 cpdef GenericBackend get_solver(constraint_generation = False, solver = None, base_ring = None):
1650 """
1651 Return a solver according to the given preferences
/home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/numerical/backends/generic_backend.pyx in sage.numerical.backends.generic_backend.get_solver (build/cythonized/sage/numerical/backends/generic_backend.c:19611)()
1794
1795 elif solver == "Cplex":
-> 1796 from sage.numerical.backends.cplex_backend import CPLEXBackend
1797 return CPLEXBackend()
1798
ImportError: /home/klara/sage-8.7/local/lib/python2.7/site-packages/sage/numerical/backends/cplex_backend.so: undefined symbol: CPXsetlogfilebucks65Tue, 21 May 2019 06:36:42 -0500http://ask.sagemath.org/question/46606/"from __future__ import print_function" fails on Sage scriptshttp://ask.sagemath.org/question/46342/from-__future__-import-print_function-fails-on-sage-scripts/Hello, Sage Community.
I am trying to use the "print" function in a .sage script, so I have added the line
from __future__ import print_function
as the first line to be included in my .sage file. Unfortunately, when running `sage test.sage`, Sage preparses the document and creates an auxiliary file "test.sage.py", which makes an import, then predefines some constants, and finally adds my preparsed code. As a consequence, the `from __future__ import print_function` is not the first line, and I get the following error message:
File "test.sage.py", line 6
from __future__ import print_function
SyntaxError: from __future__ imports must occur at the beginning of the file
Here is a MWE. The file "test.sage" containing:
from __future__ import print_function
print(1+1)
is preparsed to "test.sage.py" containing:
# This file was *autogenerated* from the file test.sage
from sage.all_cmdline import * # import sage library
_sage_const_1 = Integer(1)
from __future__ import print_function
print(_sage_const_1 +_sage_const_1 )
Of course, I could manually add this line to the .sage.py file and then execute it, but this could be tedious in my case for two reasons: 1. I have a lot of files which I have to modify and rerun every 15 minutes. 2. I also need this process to be automatic to be able to execute it with automatically generated script and even sageTeX.
Thanks in advance for your answers!dsejasWed, 24 Apr 2019 12:14:49 -0500http://ask.sagemath.org/question/46342/Load module from remote serverhttp://ask.sagemath.org/question/43778/load-module-from-remote-server/Hi, I am using a remote sage notebook public server (such as http://sage.math.canterbury.ac.nz/).
I would like to be able to load my own python modules, but I don't know how can I access local files, such as
import sys
sys.path.append('path-to-file-in-my-local-drive')
import module-name
Is there any way to do that?jllbThu, 27 Sep 2018 03:38:06 -0500http://ask.sagemath.org/question/43778/Importing Sage functions into Cython?http://ask.sagemath.org/question/42277/importing-sage-functions-into-cython/ I am trying to define variables in Cython part of my code like this
a,b,c = var('a,b,c')
But in this line I cant import var() function from Sage
from sage.calculus.var import var
I got this error:
$ sage -python real_sage.sage
Compiling ./real_sage.spyx...
Traceback (most recent call last):
File "real_sage.sage", line 6, in <module>
from real_sage import foo
File "real_sage.pyx", line 10, in init real_sage
File "sage/calculus/var.pyx", line 6, in init sage.calculus.var
File "/home/tunamustafakemal/sega/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function_factory.py", line 15, in <module>
from sage.symbolic.function import SymbolicFunction, sfunctions_funcs, \
File "sage/rings/integer.pxd", line 7, in init sage.symbolic.function
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer
File "sage/rings/rational.pyx", line 89, in init sage.rings.rational
File "sage/rings/real_mpfr.pyx", line 1, in init sage.rings.real_mpfr
File "sage/rings/complex_number.pxd", line 6, in init sage.libs.mpmath.utils
File "sage/rings/complex_double.pxd", line 10, in init sage.rings.complex_number
File "sage/rings/complex_double.pyx", line 94, in init sage.rings.complex_double
ImportError: cannot import name complex_number
Thanks for any support.tunaSun, 06 May 2018 23:14:53 -0500http://ask.sagemath.org/question/42277/Import Sage Worksheetshttp://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
ajmullinsSun, 08 Apr 2018 19:24:28 -0500http://ask.sagemath.org/question/41924/Making a collection of functionshttp://ask.sagemath.org/question/40811/making-a-collection-of-functions/I have a somewhat large collection of functions that I wrote myself to make some computations. They are all very much dependent on each other so if I ever want to use some subset of them, say when I'm working in some Jupyter notebook, I have to copy paste the whole bunch of them into a cell and evaluate it. This makes the notebook really bulky and ugly. Is there anyway I can make these functions into a package so that I can just import it in any jupyter notebook that's in the same folder to use those functions?r2d2Sat, 27 Jan 2018 13:25:00 -0600http://ask.sagemath.org/question/40811/Import just one function from .sage filehttp://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 00:21:59 -0600http://ask.sagemath.org/question/39906/Error when trying to import without sage.allhttp://ask.sagemath.org/question/40116/error-when-trying-to-import-without-sageall/I am trying to import only the Sage functions needed as is done in the Sage source code, but I am running into issues. For example, (running `sage -python`),
>>> from sage.groups.group import Group
results in
...
from sage.rings.complex_double import CDF
File "sage/rings/real_double.pxd", line 8, in init sage.rings.complex_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/complex_double.c:22654)
File "sage/rings/real_double.pyx", line 64, in init sage.rings.real_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/real_double.c:25060)
ImportError: cannot import name ZZ
(I can post the full traceback if that would be helpful.) Similar things happen for almost any import I try. I was using the `import_statements` to determine what to import.
Am I missing something?
EDIT:
I think I get the picture a little better now. The Sage source files aren't meant to be imported in Python, they are meant to be imported into Sage, which presumably runs `import sage.all` when it starts.jaebondMon, 11 Dec 2017 21:06:39 -0600http://ask.sagemath.org/question/40116/Error importing ZZhttp://ask.sagemath.org/question/35522/error-importing-zz/I'm trying to switch to a more software-development-like approach for one of my projects. To this end I'll be writing several files, and I'll be trying to keep imports to a minimum to speed up module loading.
At first I started with a file `foo.sage` and a `Makefile` which preparses this using `sage -min -preparse foo.sage`. But the resulting `foo.sage.py` still starts with `from sage.all_cmdline import *`. I thought the point of the `-min` switch was to avoid just that. Am I missing something here?
Next I tried to write Python code instead. But there I got problems, apparently because I was loading modules in the wrong order. Take for example a file `foo.py` containing just the line `from sage.rings.integer_ring import ZZ`. My Sage 7.4 on Gentoo will print the following when running said file as `sage foo.py`:
Traceback (most recent call last):
File "foo.py", line 1, in <module>
from sage.rings.integer_ring import ZZ
File "sage/rings/integer.pxd", line 7, in init sage.rings.integer_ring (…/rings/integer_ring.c:14426)
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer (…/rings/integer.c:49048)
File "sage/rings/fast_arith.pxd", line 3, in init sage.rings.rational (…/rings/rational.c:36533)
File "sage/libs/pari/gen.pxd", line 5, in init sage.rings.fast_arith (…/rings/fast_arith.c:8139)
File "sage/libs/pari/gen.pyx", line 91, in init sage.libs.pari.gen (…/libs/pari/gen.c:135191)
File "/usr/lib64/python2.7/site-packages/sage/rings/infinity.py", line 228, in <module>
from sage.rings.integer_ring import ZZ
ImportError: cannot import name ZZ
Is there a way to reasonably import things like this without too much experimentation, and without importing far more than I actually need here?MvGFri, 11 Nov 2016 04:40:15 -0600http://ask.sagemath.org/question/35522/File imports for polynomial rings in sagehttp://ask.sagemath.org/question/7584/file-imports-for-polynomial-rings-in-sage/If i type in the following
R.<z1,z2> = PolynomialRing(GF(5),2,"z")
direclty to Sage it accepts it as a polynomial ring.
But if i place this in a .py file and load it from this Sage
eg `sage my.py` it gives me a syntax error.
I guess i need a module loaded for it to be detected, but which module and hence which command do i need to make Sage accept this ring.aeThu, 19 Aug 2010 04:41:02 -0500http://ask.sagemath.org/question/7584/Importing user SAGE files "pythonically"http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/Hello,
I'm wondering if there's a more "pythonic" way in which to import user-written SAGE modules.
For instance, I'm able to load in a SAGE file I've written using the `load` keyword.
load(path_to_sage_file)
That's all well and good, however, as I start to import more and more user SAGE files, where certain functions are coming from becomes less clear. It would be ideal to do something like
from name_of_sage_file import name_of_sage_function
However, this doesn't seem to work. Is there a more "pythonic" way in which to go about doing this? Thanks!Vincent RussoSat, 09 Dec 2017 09:15:19 -0600http://ask.sagemath.org/question/40036/import CSV in python using jupyter notebook on cocalc cloudhttp://ask.sagemath.org/question/38546/import-csv-in-python-using-jupyter-notebook-on-cocalc-cloud/I want to import this [CVS file](https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data) in my python script with the commands:
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = pandas.read_csv(url, names=names)
The problem is that it returns this error message:
---------------------------------------------------------------------------
URLError Traceback (most recent call last)
<ipython-input-21-45b1e7974739> in <module>()
32 url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
33 names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
---> 34 dataset = pandas.read_csv(url, names=names)
/projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
653 skip_blank_lines=skip_blank_lines)
654
--> 655 return _read(filepath_or_buffer, kwds)
656
657 parser_f.__name__ = name
/projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
390 compression = _infer_compression(filepath_or_buffer, compression)
391 filepath_or_buffer, _, compression = get_filepath_or_buffer(
--> 392 filepath_or_buffer, encoding, compression)
393 kwds['compression'] = compression
394
/projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/common.py in get_filepath_or_buffer(filepath_or_buffer, encoding, compression)
184 if _is_url(filepath_or_buffer):
185 url = str(filepath_or_buffer)
--> 186 req = _urlopen(url)
187 content_encoding = req.headers.get('Content-Encoding', None)
188 if content_encoding == 'gzip':
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in urlopen(url, data, timeout, cafile, capath, cadefault, context)
152 else:
153 opener = _opener
--> 154 return opener.open(url, data, timeout)
155
156 def install_opener(opener):
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in open(self, fullurl, data, timeout)
427 req = meth(req)
428
--> 429 response = self._open(req, data)
430
431 # post-process response
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in _open(self, req, data)
445 protocol = req.get_type()
446 result = self._call_chain(self.handle_open, protocol, protocol +
--> 447 '_open', req)
448 if result:
449 return result
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
405 func = getattr(handler, meth_name)
406
--> 407 result = func(*args)
408 if result is not None:
409 return result
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in https_open(self, req)
1239 def https_open(self, req):
1240 return self.do_open(httplib.HTTPSConnection, req,
-> 1241 context=self._context)
1242
1243 https_request = AbstractHTTPHandler.do_request_
/projects/sage/sage-7.6/local/lib/python/urllib2.pyc in do_open(self, http_class, req, **http_conn_args)
1196 except socket.error, err: # XXX what error?
1197 h.close()
-> 1198 raise URLError(err)
1199 else:
1200 try:
URLError: <urlopen error [Errno 110] Connection timed out>
What's the problem?
How could I solve?
I use a free account on CoCalc.
If it takes time to upload and so not enough for my free account, how I can upload the file as worksheet and link it? What will be the link in the URL specification?
ThankspspWed, 16 Aug 2017 09:40:27 -0500http://ask.sagemath.org/question/38546/import print_function only works in one cell in linuxhttp://ask.sagemath.org/question/37776/import-print_function-only-works-in-one-cell-in-linux/I just installed Sage in Linux Mint, and the Import `print_function` only seems to work in one cell in the Notebook.
If I type this in the top cell it works fine:
from __future__ import print_function
print("all","good","dogs","eat","shoes",sep=" now ")
to print this:
all now good now dogs now eat now shoes
But if I do exactly the same print in the next cell, without the import, I get a syntax error.
However, the import does work for all cells in Sage for Windows.cybervigilanteFri, 02 Jun 2017 21:00:46 -0500http://ask.sagemath.org/question/37776/Import Text.txt file contents from a windows computer to sagecell.http://ask.sagemath.org/question/38185/import-texttxt-file-contents-from-a-windows-computer-to-sagecell/Hello,
The following code will work on my Linux computer if I use the "/usual path/" in Linux but I cannot get Sage to recognize
my Windows path. My code
with open('C:\Users\miram\OneDrive\Documents\Programming\Original.txt', 'r') as f:
L = f.readlines()
I have also tried the path
with open('C:\\Users\\miram\\OneDrive\\Documents\\Programming\\Original.txt', 'r') as f:
L = f.readlines()
I have also tried the path
with open('C:\\Text\\22.PE.Orig.List.txt', 'r') as f:
L = f.readlines()
and with one backslash.
I get the following error:
IOError: [Errno 2] No such file or directory: 'C:\\Text\\22.PE.Orig.List.txt'
What I want to do, as can be seen, is import a text file into SageMath so that I can work with the list created.
I am following: https://ask.sagemath.org/question/28765/turning-a-txt-file-into-a-list-in-sagemathpython/ and have followed the advice for my Linux machine and have not had a problem. I need to do it on my Windows computer, though.
I think my problem is that I am using a sagecell server. Is that true?happys5Wed, 05 Jul 2017 20:47:54 -0500http://ask.sagemath.org/question/38185/How to import numpyhttp://ask.sagemath.org/question/37959/how-to-import-numpy/ I am having problems importing numpy. I have sage 7.6 and am using terminal sessions on mac. Whenever I try "import numpy" I get an error message saying "Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there." I understand that this means some numpy software is not in the right file, but others, working on the same project as me, I know have not had to import any extra software for numpy to work. I'd really appreciate any help!TabethaFri, 16 Jun 2017 07:00:48 -0500http://ask.sagemath.org/question/37959/Import class using mathematicahttp://ask.sagemath.org/question/37229/import-class-using-mathematica/I have a class a in a file a.sage using the interface to mathematica. I want to use this class in another class b.
One way I found was to run first "mv a.sage a.py", which generates a python file. But then I get the error: "NameError: global name 'mathematica' is not defined" because you cannot use mathematica in python as you can use it with sage.
Is there a way importing a self-written class (a.sage) using mathematica in another self-written class (b.sage)?sageUserFri, 07 Apr 2017 12:34:45 -0500http://ask.sagemath.org/question/37229/How to import the print function from __future__ ?http://ask.sagemath.org/question/37014/how-to-import-the-print-function-from-__future__/I did `from __future__ import print_function`
print('text',end='\n')
But it shows error.screened00Tue, 21 Mar 2017 09:41:27 -0500http://ask.sagemath.org/question/37014/import module in SageMathCloudhttp://ask.sagemath.org/question/36471/import-module-in-sagemathcloud/Hi,
In my SMC project, I have two sagemath worksheet. I need to "import" the first one into the second one. Is there a way to do so? Can't figure it out. Thanks!
MartinmaaaaaaartinTue, 07 Feb 2017 07:52:54 -0600http://ask.sagemath.org/question/36471/What does `from sage.all import *` do?http://ask.sagemath.org/question/35483/what-does-from-sageall-import-do/This question is relatd with another one: [What packages in sage can I use in python?](http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/)
[How do I import Sage into a Python script](http://doc.sagemath.org/html/en/faq/faq-usage.html#how-do-i-import-sage-into-a-python-script) told me that to use from `sage.all import *` to import sage packages in python. When I list the installed sage packages, there is igraph and python-igraph. But `from sage.all import *` will not import them into python. I'd like to know, what kind of packages can be imported when I use `from sage.all import *`.
BTW, the proper way to use `igraph` in python is `import igraph` with `python_igraph`installed.
ps: My karma is insufficient to publish links.edenharderTue, 08 Nov 2016 12:38:49 -0600http://ask.sagemath.org/question/35483/How do I convert a notebook to a python script?http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/I'm asking this because I'm starting a project and Sage seems like a very good platform to do some prototyping.
Better yet, it might be a great way to use the code that results from my prototyping directly has the final version as well.
But for that to work with a minimal of hardship though, a few things would be usefull:
1. A way to grab the code content of a notebook and generate an independent python script or function
2. A list of libraries, with version, that every sage version uses.
3. An instalable library version of sage that could be imported from the script
4. Anything else that I'm missing and you know sage can do to help in this task
I'm not asking for a completely automatic way to do this, just for resources/scripts or general advices about how to do it.
I'm also just starting to look into sage so, don't assume to much on what I may know. ;)
Thanks.Alexandre MartinsSat, 10 Mar 2012 07:58:00 -0600http://ask.sagemath.org/question/8782/Error on %attach for import __future__http://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 03:52:31 -0500http://ask.sagemath.org/question/33946/How to import the file "function.py" to worksheet sage? sagemath loaded by virtual machine (VirtualBox)http://ask.sagemath.org/question/32474/how-to-import-the-file-functionpy-to-worksheet-sage-sagemath-loaded-by-virtual-machine-virtualbox/i want to import a file function called "function.py" to my Worksheet. How to do?jmarcellopereiraSat, 06 Feb 2016 14:12:15 -0600http://ask.sagemath.org/question/32474/Organizing files in Sage Cloud/moduleshttp://ask.sagemath.org/question/27081/organizing-files-in-sage-cloudmodules/ I am working in sage cloud, in a worksheet (sagews). I wrote some classes and methods so far and I wish to keep them separated from my new code/organize my projects in files that I can import from.
I want something like
file Resources.(.py? .sage? .sagews?) with classes Foo, Foo2, Foo3
and to use this in a new spreadsheet:
<code>
from Resources import Foo2
</code>
While this seems like a basic question, the only thing I could discover on this topic was a similar unanswered question: http://ask.sagemath.org/question/26040/import-module-from-another-file-in-cloud/
How do I do this? How do I split a project in several files(modules?) that I could import from?
WizqWed, 10 Jun 2015 06:43:12 -0500http://ask.sagemath.org/question/27081/How to import a modul from my local disk to a cloud worksheet?http://ask.sagemath.org/question/26475/how-to-import-a-modul-from-my-local-disk-to-a-cloud-worksheet/*I would like to use modules that are stored on my local hard drive in worksheets running in cloud.sagemath. I tried to type*
sys.path.append('/Users/Jorg/myPath/myModule')
from myModule import *
*However, when executing I get the message*
ImportError: No module named selfAffineTile
*What would be the right way to do this?*
*Thanks for any help,*
*Jorg*
jorgThu, 09 Apr 2015 01:32:31 -0500http://ask.sagemath.org/question/26475/How do I use a sage graph in LaTEX?http://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/I created a project in Sage that graphed multiple curves at once. Is there a way I can just import this graph or the code into LaTEX?ecain17Sun, 22 Feb 2015 21:42:20 -0600http://ask.sagemath.org/question/25896/Executing python modules from packagehttp://ask.sagemath.org/question/25041/executing-python-modules-from-package/I have a project that is primarily written in python but uses sage for some specific operations. In order to facilitate this I have only .py files and use `from sage.all import *` at the top of all modules that make use of sage functionalities. To execute I always used `sage -python path/to/file.py`.
This approach worked fine until it became necessary to split my project into multiple sub-packages. I now want to execute my modules with `python -m package.subpackage.module` for modules that do not use sage (which works) and correspondingly `sage -python -m package.subpackage.module` for modules that do. Unfortunately the latter only returns an error message of the form `~/sage/local/bin/python: No module named package.subpackage`
In order to be able to use package relative imports I am kind of dependent on the -m syntax, so I would like to get it to work. Any ideas what I am doing wrong? Or is this simply not possible with the python that is bundled with sage for internal reasons? Any help is apreciated!kekxFri, 28 Nov 2014 13:24:51 -0600http://ask.sagemath.org/question/25041/How to import in an Ipython-Notebook on SMC?http://ask.sagemath.org/question/24385/how-to-import-in-an-ipython-notebook-on-smc/ Consider the following scenario (which I tested at SageMathCloud), with an Ipython-Notebook:
%load_ext sage
import trans
def A():
""" Computes the factorial """
n, f = 1, 1
while True:
f = f*n
yield f
n += 1
def binomial_trans(seq):
""" Input : seq sequence generator """
S = []
n = 0
while True:
S.append(seq.next())
yield sum(binomial(n, k) * S[k] for k in (0..n))
n += 1
f = binomial_trans(A())
print [f.next() for _ in range(10)]
This works. Now I would like to outsource the function 'binomial_trans' in a file trans.py and compute
f = trans.binomial_trans(A())
print [f.next() for _ in range(10)]
This does not work. The error message is: AttributeError: 'float' object has no attribute 'n'
What can I do to make the import work together with Sage in an Ipython-Notebook?
Peter
Peter LuschnyFri, 03 Oct 2014 15:30:55 -0500http://ask.sagemath.org/question/24385/Optimization toolboxes under SAGEhttp://ask.sagemath.org/question/10737/optimization-toolboxes-under-sage/Can we use SAGE to solve some optimization problems? Can we import optimization toolboxes such as YALMIP, MPT, CVX, TOMLAB in SAGE?
----------
Thanks in advance!gundamlhFri, 15 Nov 2013 00:36:23 -0600http://ask.sagemath.org/question/10737/manage my functions in SAGEhttp://ask.sagemath.org/question/10723/manage-my-functions-in-sage/I prefer bash/console as my SAGE editor with both hands always on the keyboard.
However, I want to manage those functions that are defined by myself in a way as in MATLAB, explicitly store m-functions in a toolbox folder and load them using addpath/import if necessary. Moreover, it seems inconvenient to modify/extend a function in bash/console in SAGE.
EMACS is perhaps a good choice?
Thanks in advance!gundamlhSun, 10 Nov 2013 20:44:45 -0600http://ask.sagemath.org/question/10723/docstring for my .py files does not work in Sage Notebook [UPD1]http://ask.sagemath.org/question/10629/docstring-for-my-py-files-does-not-work-in-sage-notebook-upd1/Hello!
Sage 5.10, Linux Mint 15 Cinnamon. <br>
I created new directory "pycode" in /home/andrei/ <br>
There is one file my_func.py in /home/andrei/pycode <br>
The context of my_module.py:
import sage.all
def my_func(a, b, c):
"""
hello!
"""
return(a+b+c)
In Sage Notebook I do the next:
import sys # 1st cell
sys.path.append('/home/andrei/pycode/') # 2nd cell
import my_module # 3rd cell
my_module.my_func? # 4 cell
I don't see any docstring in Sage Notebook. Where is the error? Please help me. Thanks.
----------------------------------------
**UPD1:**
I found the answer! :)
First of all I turned off and then launched sage notebook. After that I saw my docstring. Then I use Action... --> Restart worksheet.
Please explain me why shift+enter doesn't work for me. Thanks.
AndreWinSat, 19 Oct 2013 00:24:54 -0500http://ask.sagemath.org/question/10629/