在docker上运行时,Python flask重新加载器“ Errno 2 No such file or directory”错误

时间:2019-03-25 17:46:10

标签: python windows docker flask

我在使用Docker运行一个Flask应用程序时遇到问题。调试关闭时一切正常,但是当我尝试在调试器上运行它时,在重新加载器阶段失败。它在Windows上可以正常运行,问题只在Docker中出现。

在我的docker仓库中,我安装了caffe和我需要的所有依赖项(烧瓶和wekrzeug)。我以为问题可能出在重新加载器上,所以我也安装了看门狗,但它仍然显示出来。我自己运行app.py还是调用python -m flask run都没有关系。

docker run --volume=%cd%:/workspace -p 5001:5000 caffe:cpu
 * Serving Flask app "app" (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://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with inotify reloader
Traceback (most recent call last):
  File "app.py", line 53, in <module>
    app.run(debug = True, host='0.0.0.0')
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 988, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

2 个答案:

答案 0 :(得分:0)

我在这里遇到了同样的问题,对我来说,解决方案是从“ run.py”文件中删除可执行标志。

  

$ chmod -x run.py

错误非常相似,但就我而言,我在Windows 10计算机上使用Ubuntu 18.04 WSL。

答案 1 :(得分:0)

尝试将应用作为模块运行:

python -m flask run

有关更多信息,请参见https://github.com/pallets/flask/issues/1829