Place the following code into main.py.
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/')
def root():
return ":)"
app.run()
Set the execute bit on main.py:
chmod +x main.py
Running the following command should start the server: python main.py
$ python main.py
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "main.py", line 11, in <module>
app.run()
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/site-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/site-packages/werkzeug/serving.py", line 988, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
sys.exit(reloader.restart_with_reloader())
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ, close_fds=False)
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/subprocess.py", line 323, in call
with Popen(*popenargs, **kwargs) as p:
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Users/wadegilmer/miniconda3/envs/hello-flask/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/Users/wadegilmer/lc101/flask_error/main.py'
Adding a shabang line to main.py resolves the issue but is kind of unexpected. Additionally removing the execute bit also resolves the issue. Is this the expected behavior?
Hello, Tried to reproduce the problem, and I have all worked. Maybe there are some other factors that could affect your script?
Environment
I reproduced this issue with Werkzeug >= 0.15.0 on macOS 10.14 (Python 3.7).
Duplicate of https://github.com/pallets/werkzeug/issues/1482. You've marked a script as executable but didn't add an interpreter comment at the top. Either add #! /usr/bin/env python or unset the executable bit. Or use the recommended flask run command to run the development server.
In my case it was permission issue. User running the script didn't have permission.
Most helpful comment
Duplicate of https://github.com/pallets/werkzeug/issues/1482. You've marked a script as executable but didn't add an interpreter comment at the top. Either add
#! /usr/bin/env pythonor unset the executable bit. Or use the recommendedflask runcommand to run the development server.