After following these steps in the Python Flask tutorial:
https://code.visualstudio.com/docs/python/tutorial-flask#_refactor-the-project-to-support-further-development
I can only run the app in the python debug console. I can't run it in powershell, although I am following the same steps, I get this error:
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.
Yes that worked. Thank you!
On Thu, Sep 27, 2018, 9:18 AM Kraig Brockschmidt notifications@github.com
wrote:
Under Powershell, you have to set the FLASK_APP environment variable as
follows:$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app
folder. In other words, PowerShell manages environment variables
differently, so the standard command-line "set FLASK_APP=webapp" won't work.Let me know if that solves your problem.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-docs/issues/1881#issuecomment-425154463,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYCluBoxxhC4DAeU3y-y5S-B3hNE_J2eks5ufPpzgaJpZM4W7uOq
.
Great! Thanks for filing the issue, too; it's not quite a detail I want to put in the docs proper, so having the issue here allows folks to find the solution if they run into the same problem.
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.
Thanks i had the same problem and that worked!!
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.
I am facing this issue in Anaconda prompt? can you help me with the solution ?
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.I am facing this issue in Anaconda prompt? can you help me with the solution ?
Have you solved it?
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
For others try export FLASK_APP=hello.py the name of your entry file being whatever you called it export FLASK_APP=app.py, export FLASK_APP=this.py upto you.
For others try
export FLASK_APP=hello.pythe name of your entry file being whatever you called itexport FLASK_APP=app.py,export FLASK_APP=this.pyupto you.
Thank you this solved the issue for me :D
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.
This work for me, thanks!!!
@JoshuaPartlow just a reminder note to check the VS Code docs and make sure the PowerShell variant reported here is included.
Set-Location C:\Userstruew\PycharmProjects\milan\webserver
(webserver) PS C:\Userstruew\PycharmProjects\milan\webserver> flask run
Error: Could not import "webapp".
I'm a new in python flask and using pycharm how to run 1st output on the web browser..where to run and how to run the commands.
its showing me this if i write "flask run" in terminal ! ?
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the curren
t directory.
@Muhammadb1094 You need to create an environment variable named FLASK_APP. See the "Tip" under step 8 in https://code.visualstudio.com/docs/python/tutorial-flask#_create-and-run-a-minimal-flask-app.
thank you it worked for me ;)
Thanks..karaigb
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
.....I can not solve this error @kraigb
Hi @Mohamedkable - What filename are you using for your Flask app? By default, a Flask looks for app.py, if you use something different then you need to set a FLASK_APP environment variable with the alternate filename. So if you used hello.py as your file, on Windows, and were running in the terminal you'd need to use "set FLASK_APP=hello.py". Where are you trying to run the Flask app from? There's some alternate guidance above from @kraigb if you're using PowerShell. The Flask cli docs also have some guidance. Does that help?
@JoshuaPartlow I do that already, but i do now work also..i run the code from Git Bash on windows
I've not tried running from Git Bash before, but you should be able to do "echo $FLASK_APP" to verify if the variable has been set correctly.
Thanks,sir
I write this code in my app that is run well but if i change the port to 5000.it do not work...
i do not know why..? @JoshuaPartlow
if __name__ == '__main__':
app.run(port=4000,debug=True)
Hi @Mohamedkable - The help I can offer is around the VS Code docs for our Flask tutorial. For general Flask issues I'd suggest looking at the documentation for Flask.
okay sir thank you
adding "python_dotenv" solved my issue in pycharm
For others try
export FLASK_APP=hello.pythe name of your entry file being whatever you called itexport FLASK_APP=app.py,export FLASK_APP=this.pyupto you.
This worked for me!
@Dharanya-Subramanian - So, to clarify, the app is running in the VS Code console, but you can't get it to run from a standard windows cmd window?
@Dharanya-Subramanian - So, to clarify, the app is running in the VS Code console, but you can't get it to run from a standard windows cmd window?
Yes Sir
@Dharanya-Subramanian - If that's the case, you likely just need to create an environment variable in your cmd window prior to running. By default, Flask looks for app.py, if you use something different (like hello.py) for your filename then you need to set a FLASK_APP environment variable with the alternate filename. So if you used hello.py as your file, on Windows, and were running in the cmd window you'd need to use set FLASK_APP=hello.py. The Flask cli docs also have some guidance.
Thank you so much sir. It works for me.
On Sun, Jun 14, 2020 at 2:09 AM Joshua Partlow notifications@github.com
wrote:
@Dharanya-Subramanian https://github.com/Dharanya-Subramanian - If
that's the case, you likely just need to create an environment variable in
your cmd window prior to running. By default, Flask looks for app.py, if
you use something different (like hello.py) for your filename then you need
to set a FLASK_APP environment variable with the alternate filename. So if
you used hello.py as your file, on Windows, and were running in the cmd
window you'd need to use set FLASK_APP=hello.py. The Flask cli docs
https://flask.palletsprojects.com/en/1.0.x/cli/ also have some guidance.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vscode-docs/issues/1881#issuecomment-643675369,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AOSJPN72HLIMJ6DV6T3BRQ3RWPPW7ANCNFSM4FXO4OVA
.
@JoshuaPartlow i was set the environment. set the FLASK_APP and FLASK_ENV both. but still get this error "Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory." let me now how to solve this
$env:FLASK_APP = "file.py" works like charm in VS code, thanks for the help
Hi @raeesanjum010 - Are you working through the VS Code Flask tutorial? If you are, generally the solution to that error is to make sure you've explicitly set the FLASK_APP environment variable to the correct file name if you haven't used the default app.py name. If you're not working on the tutorial, you might want to take a look at the Flask CLI documentation and Flask docs.
export FLASK_APP=main.py
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.I am facing this issue in Anaconda prompt? can you help me with the solution ?
after getting into directory run dir and then use traditional command set FLASK_APP = hello.py
For others try
export FLASK_APP=hello.pythe name of your entry file being whatever you called itexport FLASK_APP=app.py,export FLASK_APP=this.pyupto you.
this one is work for me
Most helpful comment
Under Powershell, you have to set the FLASK_APP environment variable as follows:
$env:FLASK_APP = "webapp"
Then you should be able to run "python -m flask run" inside the hello_app folder. In other words, PowerShell manages environment variables differently, so the standard command-line "set FLASK_APP=webapp" won't work.
Let me know if that solves your problem.