每当我使用vagrant在虚拟机上运行Flask应用程序时,都会显示错误“ OSError:[Errno 8] Exec format error”

时间:2019-07-01 18:51:58

标签: python flask vagrant virtual-machine

我是不熟悉烧瓶的人,正在尝试使用虚拟机在流浪汉中运行我的基本烧瓶代码。以下是我的代码:

from flask import Flask

app = Flask(__name__)


@app.route('/')
@app.route('/hello')
def HelloWorld():
    return "Hello World"


if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=5000)

每当我尝试在终端中以python file-name.py 的身份运行代码时,都会收到以下错误消息:

 * Serving Flask app "project" (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
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "project.py", line 14, in <module>
    app.run()
  File "/home/vagrant/.local/lib/python3.5/site-packages/flask/app.py", line 944, in run
    run_simple(host, port, self, **options)
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/serving.py", line 1007, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/usr/lib/python3.5/subprocess.py", line 557, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error

我有一台Windows计算机,并在无业游民的VM上运行以下代码。

有人可以帮助我吗?非常感谢您的帮助。

这是针对流浪者上的VM的。我试图更改端口和主机地址,我同时在python解释器(2.7和3.6)上运行,但最终都没有解析。 它在主机(在我的情况下是Windows)中可以正常运行,但在无业游民中则无法使用。

from flask import Flask

app = Flask(__name__)


@app.route('/')
@app.route('/hello')
def HelloWorld():
    return "Hello World"


if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=5000)
 * Serving Flask app "project" (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
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "project.py", line 14, in <module>
    app.run()
  File "/home/vagrant/.local/lib/python3.5/site-packages/flask/app.py", line 944, in run
    run_simple(host, port, self, **options)
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/serving.py", line 1007, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/home/vagrant/.local/lib/python3.5/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/usr/lib/python3.5/subprocess.py", line 557, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error

0 个答案:

没有答案