1

I want to run the following code (which is executable in Ubuntu) or its equivalent in Windows:

python3 -m flask run

How can I run the above code in Windows? When I write it in the command prompt, the following appears:

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

3 Answers3

5

Answer to the question: https://flask.palletsprojects.com/_/downloads/en/1.1.x/pdf/

Run the app:

set FLASK_APP=newproj
set FLASK_ENV=development
flask run

Firstly you should create virtualenvironment for your flask project in yor desktop.

  • install virtualenvironment : install virtualenvironment at your terminal or dos

    pip install virtualenv

  • create a new folder for your project (i show you creating folder at terminal)

    mkdir newproj

    cd newproj

    virtualenv venv

  • mkdir newproj : created new folder named "newproj"

  • cd newproj : change directory to "newproj"

  • virtualenv venv : created virtualenvironment named "venv"

and activate your venv.

C:\Users\name\abc> venv\Scripts\activate

Now, you can start install flask.

pip install Flask

If you use pycharm, open your folder in your editor. And create a new python file named hello.py (or another things). Write code below inside ypur python file.

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
   return 'Hello World’

if __name__ == '__main__':
   app.run()

Open pycharm editor and if venv is deactivate, activate venv. The above given Python script is executed from Python shell.

python hello.py

Debug Mode:

# app.run(debug = True)

app.run(host='127.0.0.1',port=8000,debug=True)

Summary :

$ export FLASK_APP=app.py # your python file name
$ set FLASK_APP = app.py
$ export FLASK_ENV=development
$ set FLASK_DEBUG = True
$ flask run
Ayse
  • 576
  • 4
  • 13
0

Here is a tricky part which I meet currently, for my situation I do download python too but cannot recognised via python --vesrion

try with py --version, it work in my case and use py instead of python for other command too

JuneTai
  • 26
  • 3
-1

You can try with cmd in window 10 as below:

export FLASK_APP=app.py # your python file name
set FLASK_APP = app.py
export FLASK_ENV=development
set FLASK_DEBUG = True
python -m flask run  # for window
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 29 '22 at 06:45