flask run won't work when I try it in a new conda env but works fine in an older conda env.
I've deleted and recreated new-env and reinstalled flask with the same version: 1.0.3.
(new-env) C:\Users\myname\PycharmProjects\myproject\backend>set FLASK_APP=my_app.py
(new-env) C:\Users\myname\PycharmProjects\myproject\backend>set FLASK_DEBUG=1
(new-env) C:\Users\myname\PycharmProjects\myproject\backend>flask run
* Serving Flask app "my_app.py" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
c:\users\myname\anaconda3\envs\new-env\python.exe: No module named C:\Users\myname\Anaconda3\envs\new-env\Scripts\flask
Switching to older conda env:
(old-env) C:\Users\myname\PycharmProjects\myproject\backend>flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Related
It's hard to remember when, but at one point the auto-reload function of Flask started to not work anymore in my project.
This is the output upon starting my app :
FLASK_APP = back/python/app/app.py:app
FLASK_ENV = development
FLASK_DEBUG = 1
In folder C:/path/to/project
ssh://[VirtualMachineIP]:22/root/env/bin/python3.7 -u -m flask run -h 0.0.0.0 -p 1234
* Serving Flask app 'back/python/app/app.py:app' (lazy loading)
* Environment: development
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://[VirtualMachineIP]:1234/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 106-048-128
The development environment and Debug mode are both on. Thus, upon saving changes in a file (while the app is deployed) I get the usual message :
* Detected change in '/path/to/changed/file.py', reloading
Signaling that the app is reloading with the new code. Except it doesn't reload anything, and the message doesn't appear on any further changes until I'm forced to restart the app.
PyCharms runs on Windows and communicates via ssh to my Virtual Machine, where the code is executed. I have installed the following modules:
flask
flask-socketio
eventlet
flask-cors
Any help is welcomed. Thanks :)
The FLASK_DEBUG environment variable is badly supported, it may not behave as expected if set in code. (Quoted from the source of flask).
It suggest to use flask run in debug mode.
eg: $ flask --app hello --debug run
If it still not work, you can force to use reloader like this:
if __name__ == '__main__':
app.run(host=config.HOST, port=config.PORT, debug=True)
Take care, the app.run() must be wrapped with if __name__ == '__main__'.
doc: https://flask.palletsprojects.com/en/2.2.x/config/#DEBUG
I have been using docker desktop in windows 10 and running the flask application with it. So when I change the python code the docker will auto restart and perform. We can be able to check the logs on the docker desktop's container logs. But now it just shows as below:
Serving Flask app "web_app" (lazy loading)
* Environment: development
* Debug mode: on
Instead it needs to be
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 139-055-956
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
So that I can be able to check the live logs. Let me know if there is a solution for this to see the live logs with the mentioned details.
This is my command prompt message showing the environment
(base) C:\Python\flask\url-shortener>set FLASK_APP = app.py
(base) C:\Python\flask\url-shortener>set FLASK_ENV = development
(base) C:\Python\flask\url-shortener>flask run
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
This is my app.py code
from flask import Flask
hello = Flask(name)
#hello.route('/')
def home():
return 'Hello Flask!'
Try it without the spaces around =
> set FLASK_APP=app.py
> set FLASK_ENV=development
Now try to start the server. It should work!
Hi there I would like to run my flask app in a container but I got stucked caused of a third party module. (I am using PyCharm)
This is my docker file:
FROM python:3-alpine
MAINTAINER foo
COPY app /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python3", "gateway.py"]
I run the container by this command:
docker run --name mei_converter -p 5000:5000 mei_converter:latest
And receives this:
ModuleNotFoundError: No module named 'verovio'
I already fixed the dependencies in order to run it on my local machine
Terminal: python3 gateway.py
['/usr/local/lib/python3.7/site-packages',
'/Users/max/PycharmProjects/flaskmicroservice/app',
'/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-
dynload', '/Users/max/Library/Python/3.7/lib/python/site-packages',
'/usr/local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages/verovio-
2.0.0-py3.7-macosx-10.13-x86_64.egg']
* Serving Flask app "gateway" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
This works well
I also checked the project interpreter in PyCharm and found the package as installed.
Maybe some information about this third party package could help:
It is a converter for music-encoding from these guys https://www.verovio.org/python.xhtml
and not "native python" (SWIG is necessary)
By the way.. I come from the java world and have in fact zero experience with python. I am using this flask app as an microservice for my spring boot app.
I would be grateful for any help!
You need to do in the container the same you did in your local host. That is, you need to add steps to the Dockerfile to compile verovio and use it in the container.
I have a domain, domain_name.com. On my local machine, a website is made using python flask. In the home directory of the server for domain_name.com, I put all the files in a folder 'school' and in the python3 virtual environment execute the command ./main.py runserver, which gives:
* Serving Flask app "memorizer.application" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
How do I map this to domain_name.com/school? The local machine is on ubuntu 18.04 and the server is linux millennium. I have access to the cpanel.
Below is the sequence to run the script on the server:
. cd school/
. ls
app.py memorizer.db Pipfile.lock setup.cfg
LICENSE migrations public tests
main.py passenger_wsgi.py questions tmp
memorizer Pipfile README.md tox.ini
. pwd
/home/user_name/school
. cat main.py
#!/usr/bin/env python3
from memorizer.application import manager
if __name__ == '__main__':
manager.run()
. source /home/user_name/virtualenv/school/3.5/bin/activate
(school:3.5). ./main.py runserver
* Serving Flask app "memorizer.application" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)