views.py:
#!/usr/bin/env sage -python
from django.shortcuts import render
from django.http import HttpResponse
import sys
from django.http import HttpRequest
from django.template import RequestContext, loaders
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/src/bin')
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/')
from sage.all import *
def index(request):
querystring = request.GET.get('querystring')
return HttpResponse(querystring)
PATH |
Anyone??
Anyone??As you know, I've already had several useless ideas for you on another forum :( but here is another one. Is Sage itself in your regular path? By that I mean that in my PATH I have/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/usr/texbin:/Applications/MathApps:where the last one is where I have a symbolic link to my Sage installation.lrwxr-xr-x 1 me admin 87 Oct 10 2013 sage -> /Users/.../Sage-5.12-OSX-64bit-10.6.app/Contents/Resources/sage/sageI was able to successfully do what you wanted, though, with a file#!/usr/bin/env sage -pythonfrom sage.all import *print permutations(5)Now, I just executed that file as a Unix file. When you are executing yours as a *Python* file, I get the same error as you.$ python views.pyTraceback (most recent call last):File "views.py", line 3, in <module>from sage.all import *ImportError: No module named sage.allSolution? I suppose either find a way to have Django execute it as a Unix file (not Python), or just run your entire project with "sage -python" instead of your system Python!
I have a Django project with
views.py:
#!/usr/bin/env sage -python
from django.shortcuts import render
from django.http import HttpResponse
import sys
from django.http import HttpRequest
from django.template import RequestContext, loaders
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/src/bin')
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/')
from sage.all import *
PATH |
Aha, that does make sense... And yes the Django import failed. My PATH has Python version 3.4 on it which should have been a dead giveaway since Sage runs Python 2.6? Or 2.7 I believe?Would you recommend that I attempt to use kcrisman's answer, or try to install Django in Sage's Python, OR should I use sage notebook?
On Wednesday, July 9, 2014 11:18:35 AM UTC-4, Nils Bruin wrote:On Tuesday, July 8, 2014 11:53:33 AM UTC-7, Jole Bradbury wrote:I have a Django project with
views.py:
#!/usr/bin/env sage -python
from django.shortcuts import render
from django.http import HttpResponse
import sys
from django.http import HttpRequest
from django.template import RequestContext, loaders
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/src/bin')
sys.path.append('/Users/Jole/Desktop/django_proj/mysite/sage/')
from sage.all import *Unfortunately, when I fire up my Django server on localhost, I get: No module named sage.allAs an error message. As you can see I have already tried appending to the path. My Python Path includes sage and I can see this on my Django page, however my "PATH" is
PATH
That's not the path that `sage -python` would set up, so my guess is that `views.py` doesn't actually get *executed* (and hence run in a way equivalent to `sage -python views.py`), but instead gets loaded/interpreted by whatever python is running django. You should probably try and execute
sage -python -c 'import django.shortcuts'
my guess is that that would fail, proving that you didn't install django in sage's python and hence prove that your script isn't being executed by sage's python, since that line seems to execute properly in your situation.
If you want to use both django and sage in the same python, you have to ensure that both are available to the same python. The easier way to accomplish that is probably to install django in sage's python, since sage has its own python for a reason. I have no experience with django, nor a clear idea what it does, so I have no idea whether it's a good/feasible plan to mix the two. If django is a web-server, then you should probably tread very carefully. Math software and web services mix badly, because math software is usually written with no concern for security (it's written for a situation where one trusts the user), but for web software security is vital.
Things like sagecell and MathCloud put a *lot* of work in mitigating the security holes that are virtually unavoidable in making large parts of math software available via web services.
--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.