Using TensorFlow with Sage
Question: 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). The Sage part works on its own, and the TensorFlow part
works on its own, but I can't figure out how to get them working together.

Specifically: I can make a file test.py using Sage functions and run it from
the command line using:

    
    
    sage --python test.py
    

with no problem. But calling a function defined in test.py from a .py file
using TensorFlow fails ("Import error, no module named Sage"), presumably
because Sage (6.x) uses Python 2.6.x, while TensorFlow uses Python 2.7 or
3.3+.

Is there a way around this?

Thanks!

EDIT: 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'`.

I just upgraded to Sage 7.0 if that matters (this didn't work in 6.10 either,
though).


Answer: Here's something **NOT** to do (yet); don't just take whatever Sage install
you happen to have and do:

    
    
    $ sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
    

Even though this "works", it also had several worrying messages about
upgrading numpy and six, which completely broke the numpy part of my Sage
installation. This was with Sage-6.9.

Which means you have to make sure you have a Sage that has the right versions
of Numpy and six. With the latest development version, we do, apparently:

    
    
    $ cd /path/to/my/bleeding/edge/sage/directory
    $ ./sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
    Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
      Using cached https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
    Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in ./local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==0.7.1)
    Collecting protobuf==3.0.0b2 (from tensorflow==0.7.1)
      Using cached protobuf-3.0.0b2-py2.py3-none-any.whl
    Collecting wheel (from tensorflow==0.7.1)
      Using cached wheel-0.29.0-py2.py3-none-any.whl
    Requirement already satisfied (use --upgrade to upgrade): numpy>=1.10.1 in ./local/lib/python2.7/site-packages (from tensorflow==0.7.1)
    Requirement already satisfied (use --upgrade to upgrade): setuptools in ./local/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg (from protobuf==3.0.0b2->tensorflow==0.7.1)
    Installing collected packages: protobuf, wheel, tensorflow
    Successfully installed protobuf-3.0.0b2 tensorflow-0.7.1 wheel-0.29.0
    You are using pip version 8.0.2, however version 8.1.0 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    

And then I don't get any failures.

So one has to be careful, but apparently it's possible. However, you
definitely have to use it from "within" Sage; Sage-as-distribution wouldn't
allow you to use your other tensorflow with it.

