Flask application problem on Jupyter notebook installed through Anaconda

2,379 views
Skip to first unread message

ssarkaray...@gmail.com

unread,
Jul 7, 2018, 10:55:30 PM7/7/18
to Project Jupyter
Hello,

I have a python application using Flask.  It runs fine from command prompt on Windows 10.
But when I try to run the same application from Jupyter Notebook (from Anaconda), I get following error for the
call :   app.run(debug=True, port=8000)

The error I get: 

UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-13-b728e01956cc> in <module>()
----> 1 app.run(debug=True, port=8000)

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\flask\app.py in run(self, host, port, debug, load_dotenv, **options)
    936         options.setdefault('threaded', True)
    937
--> 938         cli.show_server_banner(self.env, self.debug, self.name, False)
    939
    940         from werkzeug.serving import run_simple

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\flask\cli.py in show_server_banner(env, debug, app_import_path, eager_loading)
    627             message += ' (lazy loading)'
    628
--> 629         click.echo(message)
    630
    631     click.echo(' * Environment: {0}'.format(env))

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\click\utils.py in echo(message, file, nl, err, color)
    257
    258     if message:
--> 259         file.write(message)
    260     file.flush()
    261

UnsupportedOperation: not writable Can I get some help Please ? Thanks, S. Sarkar


Roland Weber

unread,
Jul 11, 2018, 1:43:17 AM7/11/18
to Project Jupyter
You cannot run a permanent server inside a notebook kernel. Or more precisely, it doesn't make sense. The kernel is there to execute code snippets from a notebook or other client and return the output and results, not to permanently run a server application that listens on a different port. If you want to run a permanent server that listens on its own port, then start it from the command line. The notebook kernel doesn't add any value for that use case.

Shaurya Khurana

unread,
Dec 25, 2018, 1:04:29 AM12/25/18
to Project Jupyter
This is an internal issue of Jupyter Notebook, as it doesn't support this functionality. However, you can run this manually:
(Append this code at the end)

# starting the app on port
try: 
    # works fine while running the py script in the command-line 
    app.run(debug=True,port=8000)
except:
    # internal issue with Jupyter Notebook
    print("Exception occured!")
    # running manually
    from werkzeug.serving import run_simple
    run_simple('localhost', 9000, app)
Reply all
Reply to author
Forward
0 new messages