Hey Folks,
I have a Flask application working on my local machine that I am having trouble porting over to PythonAnywhere. It is an NFL data app. The app takes inputs from a URL, fills in an ipython notebook template with the values from the URL, runs the ipython notebook, converts the new notebook to html, and serves it.
The function is here:
import IPython
from IPython import nbformat
from IPython.nbconvert.preprocessors.execute import ExecutePreprocessor
from IPython import nbconvert
import os
import sys
path = '/home/gitzman/FootballAnalysis/'
sys.path.append(path)
def editNotebook(start,end=7):
nb = nbformat.read(path+"3danalysis.ipynb", as_version=4)
nb.cells[0]["source"]=nb.cells[0]["source"].format(start,end)
nb.cells[3]["source"]=nb.cells[3]["source"].format(start,end,end+1)
pp = ExecutePreprocessor()
pp.timeout = 30 # seconds
pp.interrupt_on_timeout = True
nb_executed, resources = pp.preprocess(nb, resources={})
directory="static/"
filename=str(start)+str(end)+"export"
with open(path+directory+filename+".ipynb", 'w') as f:
f.write(nbformat.v4.writes_json(nb_executed))
os.system('ipython nbconvert {0} --to html --output {1}'.format(path+directory
+ filename+".ipynb" ,path+directory+ filename+".html"))
return filename+".html"
Something is happening in this line:
nb_executed, resources = pp.preprocess(nb, resources={})
It looks like there is something odd happening with kernel creation when I try to host this as a website.
This is the error message:
2015-11-02 20:11:35,956 :Exception on /3d/3 [GET]
Traceback (most recent call last):
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/gitzman/FootballAnalysis/flasky.py", line 17, in thirdd
return app.send_static_file(makenotebook.editNotebook(start))
File "/home/gitzman/FootballAnalysis/makenotebook.py", line 22, in editNotebook
nb_executed, resources = pp.preprocess(nb, resources={})
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/IPython/nbconvert/preprocessors/execute.py", line 55, in preprocess
cwd=path)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/IPython/kernel/manager.py", line 420, in start_new_kernel
km.start_kernel(**kwargs)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/IPython/kernel/manager.py", line 240, in start_kernel
**kw)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/IPython/kernel/manager.py", line 189, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/home/gitzman/.virtualenvs/football/local/lib/python2.7/site-packages/IPython/kernel/launcher.py", line 213, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I hope that somebody can help me to get this working, as I've been trying to deploy this for a few days and I feel very close at this point. If you need any additional code, like the flask app that calls this function, or the ipython notebook being edited, please let me know.
Thank you!
-Incredibly Appreciative!