Flask help

376 views
Skip to first unread message

janis....@gmail.com

unread,
May 16, 2018, 8:46:24 AM5/16/18
to thonny
My settings are:

Beginner at Python
Windows 10
Python 3.6
pip installed on Python
Thonny 2.1 - installed with Python pip
basically I haven't used classical Python, but write code through Thonny and manage packages as well - probably the only packages that I've installed on Python are pip and Thonny
All the other packages(not that many) are installed through Thonny package manager - and they work.


The problem:

Installed Flask on Thonny
tried to run this code:

########
# CODE#
########
from flask import Flask
app = Flask(__name__)

@app.route('/')
def homepage():
    return """
    Hello world!
    This is my first web app!
    """

if __name__ == '__main__':
    app.run(use_reloader=True)
########
# CODE#
########


It throws out error, if launched on Thonny via GUI:
OSError: Windows error 1

It runs, if installed Flask on python via pip and when launching it by console, so it generates HTML page on localhost:5000

What is the difference? Why python can run it and can code be run by Thonny GUI?
Do I have to set something? It's not a big deal at the moment, but I like using Thonny GUI option to run script(while learning and writing code), than firing up console and create clutter on desktop.

Aivar Annamaa

unread,
May 16, 2018, 1:02:04 PM5/16/18
to thonny
Hi Janis!

I was able to reproduce this error. From the stracktrace it looks like Flask (or more precisely its dependency called "click") assumes it is run on a terminal emulator. Unfortunately Thonny's shell currently doesn't attempt to be a terminal emulator.

I created an issue for this (https://bitbucket.org/plas/thonny/issues/430/try-to-support-more-programs-which-expect) and try to do something about it (but probably not in the near future). 

As a workaround you should be able to run it in system terminal (Tools => Open system shell) . I hope to add alternative run command for Thonny 2.2, which opens the program in terminal (https://bitbucket.org/plas/thonny/issues/391/allow-running-programs-in-the-system)

best regards,
Aivar
Reply all
Reply to author
Forward
0 new messages