Running Flask in Windows doesn't see environment variable

how to run flask app on windows
flask' is not recognized as an internal or external command
flask run python script
pip install flask not working
how to install flask in anaconda
flask run --port
how to install flask in pycharm
flask cli

I want to set an environment variable DATABASE_URL that will be read by my Flask app to connect to the database. I use set DATABASE_URL = '...', but I get an error that the variable is not set when I do flask run. Why isn't this working?

import os

from flask import Flask
from sqlalchemy import create_engine

app = Flask(__name__)

if not os.getenv("DATABASE_URL"):
    raise RuntimeError("DATABASE_URL is not set")

engine = create_engine(os.getenv("DATABASE_URL"))

I navigate to the installed directory for project1 and do the following in Windows 10 cmd.exe:

set FLASK_APP = application.py
set FLASK_DEBUG = 1
set DATABASE_URL = 'postgres.......' (the credential given by the Heroku account)
flask run

Flask runs, I go to localhost:5000, and get the following error:

Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "C:\Program Files\Python36\learningPython\web_CS50\project1\application.py", line 12, in <module>
    raise RuntimeError("DATABASE_URL is not set")
RuntimeError: DATABASE_URL is not set 

Just remove spaces from set command

set FLASK_APP=application.py
set FLASK_DEBUG=1
set DATABASE_URL='postgres.......'

More at https://ss64.com/nt/set.html

How to debug a Flask app, No more struggles Windows Python development! I've found Pip Install Flask! Make a Virtual Environemt: Lets call it HelloWold. All we do in a So, the flask application I have created doesn't work & ends with an exception Python development is not presently supported in Visual Studio for Mac. On Mac and Linux, use the Python extension in Visual Studio Code. Step 1-1: Create a Visual Studio project and solution. In Visual Studio, select File > New > Project, search for "Flask", and select the Blank Flask Web Project template.

A quick idea to try:

  1. On Windows, use setx instead of set to modify the system environment variables.

    setx FLASK_APP = application.py

  2. Start a new command processor to see the variables reflected in your environment (They get set when the shell is initialized).

systems. It was designed especially for development purposes and performs poorly under high load. For deployment setups have a look at the Application Deployment pages. If python-dotenv is installed, running the flask command will set environment variables defined in the files.env and.flaskenv. This can be used to avoid having to set FLASK_APP manually every time you open a new terminal, and to set configuration using environment variables similar to how some deployment services work.

Personally, when i used flask run, i had an issue. I get this message "'flask' is not recognized as an internal or external, operable program or batch file" what could be the issue.

Windows PowerShell: > $env:FLASK_APP = "hello" > flask run. While FLASK_APP supports a variety of options for specifying your application, most use cases  In the terminal, run the app by entering python3 -m flask run (macOS/Linux) or python -m flask run (Windows), which runs the Flask development server. The development server looks for app.py by default. When you run Flask, you should see output similar to the following:

Application did not run with `flask run` with FLASK_DEBUG=1(But can run by using command`python -m flask run`) in Win10 #2083. Closed. No more struggles Windows Python development! I’ve found this is the best way to configure your dev environment. This has made things much easier to get started and less of a headache overall. We use Virtual Environment so we can test python code in encapsulated environments and to also avoid filling our base Python installation with a bunch

In this video I show you how to install Flask and create a simple app on Windows. You'll need Duration: 9:03 Posted: Jan 8, 2019 So to get the full path for flask, you can run this command (I see you're on Windows, so my apologies if this isn't 100% right, I'm basing this off of how it works on Linux): (venv) where flask /path/to/my_virtualenv/bin/flask <-- should have a result that looks like this (venv) deactivate

On Windows: py -3 -m venv venv. If you needed to install virtualenv because you are on an older version of Python, use the following command  The following is a step-by-step guide to get you started using Python for web development on Windows, using the Windows Subsystem for Linux (WSL). We recommend installing Python on WSL when building web applications. Many of the tutorials and instructions for Python web development are written for Linux users and use Linux-based packaging and

Comments
  • Holy crap I can't believe that worked. Also, I had to put in the connection string with no quotes at all. e.g.: set DATABASE_URL=postgres.......