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.Wed, 28 Feb 2018 13:34:14 -0600SAGE 8.1, cannot import python modules from notebookhttp://ask.sagemath.org/question/41315/sage-81-cannot-import-python-modules-from-notebook/I'm running into trouble trying to setup SAGE 8.1.
What happened is the following.
I'm working in Linux Ubuntu 16.4. I installed SAGE 7.5.1 from command-line. Then I installed SAGE 8.1 from pre-built binaries. I deleted the old sage version and now when I run the command sage, it tries to find SAGE 7.5.1 and fails.
I already ran:
ln -s /SageMath8.1/sage /usr/local/bin/sage
And nothing changed. Even though I can run SAGE 8.1 with:
/SageMath8.1/.sage
But once there I cannot import python modules:
>>> import pandas as pd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-17-af55e7023913> in <module>()
----> 1 import pandas as pd
ImportError: No module named pandas
I guess there's a problem with paths, but I don't know how to solve it.
Any help?
daranhaWed, 28 Feb 2018 13:34:14 -0600http://ask.sagemath.org/question/41315/Using Sage with TensorFlowhttp://ask.sagemath.org/question/32743/using-sage-with-tensorflow/I've written something in TensorFlow that makes use of some nice group theory functions that work very easily in Sage (and seem prohibitively difficult to code from scratch). However, I can't get TensorFlow and Sage to work together. Each works on its own, but I think they rely on different Python versions and therefore won't run together. I think Sage uses Python 2.6 and TensorFlow 2.7.
Specifically, I can make a small Python script test.py that uses some Sage functions and run it using
> sage --python test.py
and it runs with no problem. But trying to import the TensorFlow module in test.py throws an error saying the tensorflow module doesn't exist. Similarly, I get errors trying to import sage.all inside my .py script that uses TensorFlow. So I can neither add TensorFlow to Sage nor add Sage to Tensorflow.
I first encountered this problem in Sage 6.10 and upgrading to Sage 7.0 hasn't helped.
I'm not sure if this is relevant, but if I fire up normal Python (the kind TensorFlow uses), I get this:
> from sage.env import SAGE_LOCAL
> SAGE_LOCAL
which outputs `'$SAGE_ROOT/local'`.
However if I fire up Sage first I get this:
> sage
> SAGE_LOCAL
which outputs '`'/usr/lib/sagemath/local'`.
Any possible workaround?
Thanks!zqcmWed, 09 Mar 2016 06:04:12 -0600http://ask.sagemath.org/question/32743/Internal Python: `No module named all`http://ask.sagemath.org/question/7517/internal-python-no-module-named-all/## Please Note
This is not a duplicate because the other people who've got that error message all were using an external python installation instead of `sage -python /path/to.py`
## My Situation
I'm **not able to** execute scripts the following ways:
- `sage /path/to.sage` (preprocessed)
- `sage /path/to.spyx`
- `sage /path/to.py`
- `sage -python /path/to.py`
But I'm able to run correctly **without problems**:
- `sage $ load 'file'`
## The Traceback
When `cython` compiles an `.spyx` file:
Traceback (most recent call last):
[...]
File "_home_user_Dokumente_oak_code_sage_spyx_0.pyx", line 14, in init _home_user_Dokumente_oak_code_sage_spyx_0 (_home_user_Dokumente_oak_code_sage_spyx_0.c:754)
sg.var('a b c')
AttributeError: 'module' object has no attribute 'var'
The statement that there's no `var` in the loaded module seems to be true because `dir(sg)` wasn't able to find anything else than `__doc__` and other "underscored items".
When `python` tries to execute file (normal handwritten `.py` or a `sage` preprocessed `.sage`):
Traceback (most recent call last):
File "sage2.py", line 2, in <module>
from sage.all_cmdline import * # import sage library
File "/home/user/Dokumente/oak/code/sage.py", line 4, in <module>
import sage.all as sg
ImportError: No module named all
## The Source
#!/usr/bin/env sage -python
import sys
import sage.all as sg
print '== TESTOUTPUT =='
sg.var('a b c')
## The Environment
My system setup:
Ubuntu 12.4 LTS
743,6 MiB64
AMD Athlon(tm) II X4 620 Processor
64 Bit
My environment variables:
[...]
declare -x LD_LIBRARY_PATH="/opt/sage/local/lib"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LIBRARY_PATH="/opt/sage/local/lib/"
[...]
declare -x PATH="/opt/sage:/opt/sage/local/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
declare -x PWD="/home/jk/Dokumente/oak/code"
declare -x PYTHONHOME="/opt/sage/local"
declare -x PYTHONPATH="/opt/sage/local/lib/python"
declare -x RANLIB="ranlib"
declare -x RHOME="/opt/sage/local/lib/R"
declare -x RM="rm"
declare -x SAGE64="no"
declare -x SAGE_DATA="/opt/sage/data"
declare -x SAGE_DOC="/opt/sage/devel/sage/doc"
declare -x SAGE_EXTCODE="/opt/sage/spkg/installed/extcode-5.7"
declare -x SAGE_LOCAL="/opt/sage/local"
declare -x SAGE_ORIG_LD_LIBRARY_PATH="/opt/sage//local/lib"
declare -x SAGE_ORIG_LD_LIBRARY_PATH_SET="True"
declare -x SAGE_PACKAGES="/opt/sage/spkg"
declare -x SAGE_ROOT="/opt/sage"
declare -x SAGE_SERVER="http://www.sagemath.org/"
declare -x SAGE_SHARE="/opt/sage/local/share"
declare -x SAGE_STARTUP_FILE="/home/user/.sage//init.sage"
declare -x SAGE_TESTDIR="/home/user/.sage//tmp"
[...]
declare -x __sage__=""
## The Question
How can I get `sage -python` (`sage`'s internal `python`) to **execute** the files specified as command line argument **correctly**? How can I get `sage.all`'s members to get `import`ed correctly?
Thanks - if anything's unclear concerning my question, please leave a comment. fdj815Tue, 05 Mar 2013 07:43:39 -0600http://ask.sagemath.org/question/7517/How do I get sage to honor my PYTHONPATH environmental variable?http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/I have a number of modules that I have in my documents folder but sage does not look like it honors my PYTHONPATH environmental variable. What do I have to add to my .bashrc or .bash_profile to have sage look at alternate paths?bobby_mendozaMon, 28 Feb 2011 10:54:52 -0600http://ask.sagemath.org/question/7934/Writing re-usable sage scriptshttp://ask.sagemath.org/question/8005/writing-re-usable-sage-scripts/I'm looking to write some reusable code to do things like parse a particular file format outputted by some of my tools, but I don't see a particularly obvious "right way" to do this. I can define a python module, add it to the python path using the init.sage file, and then import it, but then I don't get some of the nice features I would get if I just loaded a .sage file from my current directory (namely tab-complete...).
Is there a preferred directory where I can save .sage files for use with the "load" commmand? If so, is there a way to specify a directory that is not in the SAGE_ROOT area, so I can source-control my specific .sage files independent of the sage installation?
ThanksNevilleSThu, 17 Mar 2011 05:00:10 -0500http://ask.sagemath.org/question/8005/Using mysql in conjuntion with Sage?http://ask.sagemath.org/question/7912/using-mysql-in-conjuntion-with-sage/Hello,
I'm using Ubuntu (new to it), and am really excited about Sage. I can't afford Matlab. I would like to interface Sage/Python with MySql. I've already installed MySql according to this [link](http://www.cyberciti.biz/faq/install-mysql-server-5-on-ubuntu-linux/).
I tried the command import MySQLdb, but it didn't work. The output from my terminal is pasted below.
> johndoe@johndoe:~$ python Python 2.6.6
> (r266:84292, Sep 15 2010, 15:52:39)
> [GCC 4.4.5] on linux2 Type "help",
> "copyright", "credits" or "license"
> for more information.
> >>> import MySQLdb Traceback (most recent call last): File "<stdin>",
> line 1, in <module> ImportError: No
> module named MySQLdb
> >>> quit Use quit() or Ctrl-D (i.e. EOF) to exit
> >>> quit() johndoe@johndoe:~$ cd ~/Sage johndoe@johndoe:~/Sage$ ./sage
> ---------------------------------------------------------------------- | Sage Version 4.6.1, Release Date:
> 2011-01-11 | |
> Type notebook() for the GUI, and
> license() for information. |
> ---------------------------------------------------------------------- sage: import MySQLdb
> --------------------------------------------------------------------------- ImportError
> Traceback (most recent call last)
>
> /home/johndoe/Sage/<ipython console>
> in <module>()
>
> ImportError: No module named MySQLdb
> sage: sage:
I believe I have the same problem as discussed [here](http://binarybison.com/tag/mysqldb/)
However, I'm so new to Ubuntu, that I don't quite follow. I followed the instructions and ran
import sys
for path in sys.path:
print path
I then received the output pasted below.
/home/johndoe/Sage/local/bin
/home/johndoe/Sage/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-i686.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/zope.interface-3.6.1-py2.6-linux-i686.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/zope.proxy-3.6.0-py2.6-linux-i686.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/zope.exceptions-3.6.1-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/zope.testing-3.9.5-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/ZConfig-2.8.0-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/zdaemon-2.0.4-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/ZODB3-3.7.0-py2.6-linux-i686.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/Pygments-1.3.1-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/Jinja2-2.5.5-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg
/home/johndoe/Sage/local/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg
/home/johndoe/Sage/devel/sagenb
/home/johndoe/Sage/local/bin
/home/johndoe/Sage/local/lib/python
/home/johndoe/Sage/local/lib/python26.zip
/home/johndoe/Sage/local/lib/python2.6/plat-linux2
/home/johndoe/Sage/local/lib/python2.6/lib-tk
/home/johndoe/Sage/local/lib/python2.6/lib-old
/home/johndoe/Sage/local/lib/python2.6/lib-dynload
/home/johndoe/Sage/local/lib/python2.6/site-packages
/home/johndoe/Sage/local/lib/python2.6/site-packages/PIL
/home/johndoe/Sage/local/lib/python2.6/site-packages/IPython/Extensions
/home/johndoe/.sage/ipython
However, I don't understand how to use this information to update the PYTHONPATH environment variable or the library path.
Can anyone help? My basic dilemma is how to use the programming power of python, and the mathematical power of sage together, to analyze data stored in a mysql database.
Thanks,
William
William SmytheSat, 29 Jan 2011 18:30:41 -0600http://ask.sagemath.org/question/7912/