Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[Errno 2] No such file or directory" on flask run with FLASK_DEBUG=1 #1829

Closed
yoavram opened this issue May 29, 2016 · 30 comments
Closed

"[Errno 2] No such file or directory" on flask run with FLASK_DEBUG=1 #1829

yoavram opened this issue May 29, 2016 · 30 comments

Comments

@yoavram
Copy link

yoavram commented May 29, 2016

I get the following [Errno 2] No such file or directory with flask 0.11 & werkzeug 0.11.10 on Windows 7 64bit with Python 3.5 but only when FLASK_DEBUG=1.

D:\tmp
λ python --version
Python 3.5.1 :: Continuum Analytics, Inc.

D:\tmp
λ python -c "import hello_flask"

D:\tmp
λ set FLASK_APP=hello_flask.py

D:\tmp
λ flask run
 * Serving Flask app "hello_flask"
 * Forcing debug mode off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

D:\tmp
λ set FLASK_DEBUG=1

D:\tmp
λ flask run
 * Serving Flask app "hello_flask"
 * Forcing debug mode on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with windowsapi reloader
d:\anaconda3\envs\flask\python.exe: can't open file 'D:\Anaconda3\envs\flask\Scripts\flask': [Errno 2] No such file or directory

hello_flask.py is the minimal app from the docs.

@gledi
Copy link

gledi commented May 30, 2016

I faced the same error. However it works when I run it as a module:

$ python -m flask run

@mitsuhiko
Copy link
Contributor

This might fall under the same issue as #1847.

@andersea
Copy link

andersea commented Jun 7, 2016

There is a question on stackoverflow for this issue:

http://stackoverflow.com/questions/37650208/flask-cant-find-app-file

@untitaker untitaker added the bug label Jun 7, 2016
@dgbillotte
Copy link

I'm having the same problem on Windows Server with Flask 0.11.1 except when I try

$ python -m flask run

I get: ImportError: cannot import name Flask

Currently I can only make it work with FLASK_DEBUG=0

I'd be happy to provide any other details...

@davidism davidism added the cli label Jun 26, 2016
@th0mas
Copy link

th0mas commented Jun 30, 2016

This is caused as python is looking for a script named flask, but on windows it is called flask.exe.

As a temporary fix you can copy and paste flask.exe, and just rename it 'flask'

@yoavram
Copy link
Author

yoavram commented Jul 1, 2016

Good call @TomIsPrettyCoool.
So this is a bug in the reloader - note that windows finds flask when prompted to, although it's flask.exe. the werkzeug reloader probably calls flask instead of flask.exe.
I imagine there are two ways to solve this: (1) fix the reloader to use flask.exe on windows; (2) add batch file called flask next to flask.exe during flask install. (2) is probably easier and contained in flask, but (1) might solve future bugs for other packages.

@ferbecab03
Copy link

ferbecab03 commented Dec 9, 2016

I am unable to currently replicate the bug as it uses stat instead of the windowsapi reloader.


C:\Users\Fer Ben\Documents\GitHub\flask>set FLASK_DEBUG=0

C:\Users\Fer Ben\Documents\GitHub\flask>flask run
 * Serving Flask app "hello_flask"
 * Forcing debug mode off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

C:\Users\Fer Ben\Documents\GitHub\flask>set FLASK_DEBUG=1

C:\Users\Fer Ben\Documents\GitHub\flask>flask run
 * Serving Flask app "hello_flask"
 * Forcing debug mode on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 183-411-740

@ferbecab03
Copy link

It seems it doesn't happen with the new updated version of werkzeug since it uses the stat reloader if you don't have the watchdog package installed.

@mitsuhiko
Copy link
Contributor

If you run into this you can temporarily use python -mflask. I encountered the same thing recently. Need to see what this is. I think it's that it looks for flask but it should look for flask.exe.

@ferbecab03
Copy link

I am trying to replicate the bug to see if if implementing the batch file fix was feasible. However, I am having difficulty trying to get the error to come up. Any suggestions?

@mitsuhiko
Copy link
Contributor

mitsuhiko commented Dec 9, 2016

I saw it happen on Python 3 in a virtualenv. Not sure if that's the key.

@ferbecab03
Copy link

ferbecab03 commented Dec 9, 2016

It could be. Currently running Python 3.5.2 and also an updated werkzeug.

@ferbecab03
Copy link

@mitsuhiko What would you propose to follow up on next? Since the new werkzeug changed the reloader.

@mitsuhiko
Copy link
Contributor

@ferbecab03 fix it in werkzeug. Btw I wonder if the issue also happens if you run it as "flask.exe" instead of "flask" from the command line.

@yoavram
Copy link
Author

yoavram commented Dec 10, 2016

I can't help with this - no longer using a Windows machine...

@mitsuhiko
Copy link
Contributor

This should be fixed on the Werkzeug 0.11 branch.

@ferbecab03
Copy link

Is the issue then closed because of the new update?

@mitsuhiko
Copy link
Contributor

I need to release it still. Was kinda hoping someone would test this on windows since I'm not with a windows machine currently.

@y2kbugger
Copy link

y2kbugger commented Dec 15, 2016

@ALL I have noticed that is is sufficient to use --reload to reproduce the bug as well

@mitsuhiko - the fix needed some tweaking an might need something more (or there could be an unrelated issue)

Firstly, I noticed that the fix checked for 'NT', but on my system at least, os.name returns 'nt', I've updated this to handle either case.

After more digging I notice that your .exe fix was being applied to the wrong arg .../python.exe rather than .../flask.

Here is a working fix:
y2kbugger/werkzeug@cb0eb47

HOWEVER...
At first I didn't realize that it was in fact reloading and serving correctly because now I get this long traceback and error on each reload.

Traceback (most recent call last):
  File "c:\anaconda2\envs\pytread\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\api.py", line 146, in run
    self.queue_events(self.timeout)
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\read_directory_changes.py", line 77, in queue_eve nts
    winapi_events = read_events(self._handle, self.watch.is_recursive)
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\winapi.py", line 347, in read_events
    buf, nbytes = read_directory_changes(handle, recursive)
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\winapi.py", line 307, in read_directory_changes
    raise e
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\winapi.py", line 303, in read_directory_changes
    ctypes.byref(nbytes), None, None)
  File "c:\anaconda2\envs\pytread\lib\site-packages\watchdog\observers\winapi.py", line 108, in _errcheck_bool
    raise ctypes.WinError()
OSError: [WinError 87] The parameter is incorrect.

This seems to be a separate outstanding issue with the watchdog package. Watchdog used when installed or else werkzeug falls back stats. gorakhargosh/watchdog#296
I DO NOT get this error when running as python -m flask run so it must be avoidable, but I cannot figure it out.

@mitsuhiko
Copy link
Contributor

This is now fixed in Werkzeug 0.11.13. Sorry it took a while but I did not have a windows PC with me until now.

@dimitris-k
Copy link

dimitris-k commented Oct 20, 2017

I am still getting the same behavior, when trying to run a packaged application, without installing and also using the FLASK_DEBUG=1 ... 😕

Inside a virtualenv using Ubuntu 16.04.3 LTS

pip list output:

Package      Version
------------ -------
click        6.7
Flask        0.12.2
gunicorn     19.7.1
itsdangerous 0.24
Jinja2       2.9.6
MarkupSafe   1.0
pip          9.0.1
setuptools   36.5.0
Werkzeug     0.12.2
wheel        0.30.0

Then python -m flask run works ...
FLASK_APP=myapp FLASK_DEBUG=1 python -m flask run --host 0.0.0.0

but flask run does not ...
FLASK_APP=myapp FLASK_DEBUG=1 flask run --host 0.0.0.0

 * Serving Flask app "myapp"
 * Forcing debug mode on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 119-502-443
195.xxx.xxx.xxx - - [20/Oct/2017 15:11:16] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 184, in __call__
    self._flush_bg_loading_exception()
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 172, in _flush_bg_loading_exception
    reraise(*exc_info)
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 161, in _load_app
    self._load_unlocked()
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 176, in _load_unlocked
    self._app = rv = self.loader()
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 237, in load_app
    rv = locate_app(self.app_import_path)
  File "/d2/home/dimitris/webapps/myapp/lib/python2.7/site-packages/flask/cli.py", line 100, in locate_app
    'ensure the extension is .py' % module)
NoAppException: The file/path provided (myapp) does not appear to exist.  Please verify the path is correct.  If app is not on PYTHONPATH, ensure the extension is .py

@docsteveharris
Copy link

I too am getting the same problem.

(venv) ~/c/t/flask-tutorial ❯❯❯ flask run
Usage: flask run [OPTIONS]

Error: The file/path provided (flaskr) does not appear to exist.  Please verify the path is correct.  If app is not on PYTHONPATH, ensure the extension is .py

The fix suggested worked but it took me along time to find the suggestion.

venv) ~/c/t/flask-tutorial ❯❯❯ python -m flask run                                                                 ⏎
 * Serving Flask app "flaskr" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 109-653-199

My pip list FWIW

click (6.7)
Flask (1.0.1)
itsdangerous (0.24)
Jinja2 (2.10)
MarkupSafe (1.0)
pip (9.0.1)
setuptools (28.8.0)
Werkzeug (0.14.1)

@tatianafrank
Copy link

What is the equivalent of 'python -m flask run' if I am importing the python flask library and using

import flask from Flask
app = Flask(__name__)
app.run(host='0.0.0.0', port=8000, debug=True)

Currently Im getting the same error can't open file '<>/start': [Errno 2] No such file or directory and Im on Python@3.5.3

@davidism
Copy link
Member

davidism commented Oct 16, 2019

If you want to run the CLI programatically, it would be:

from flask.cli import main
main(["--port", "8080"])

Your example suggests you're trying to use the development server in production (binding to the public with 0.0.0.0). Do not do this, use production WSGI and HTTP servers, see the deployment docs.

@tatianafrank
Copy link

No Im trying to run the server locally and have the server update with changes every time I save a file during development which is why Im trying to use debug=True which is not working... I dont think your answer addresses that issue...

@davidism
Copy link
Member

davidism commented Oct 18, 2019

Do export FLASK_ENV=development before flask run. This, and the rest of the CLI behavior, is documented here: https://flask.palletsprojects.com/en/1.1.x/cli/#environments

@y2kbugger
Copy link

y2kbugger commented Oct 18, 2019 via email

@tatianafrank
Copy link

Im using nginx for the web server. But when you say "use production WSGI" what do you mean because I see in the documentation it says "Just remember that your Flask application object is the actual WSGI application." So what more do I need to do in terms of WSGI?

@tatianafrank
Copy link

@u007
Copy link

u007 commented Feb 23, 2020

in my case due to carriage return, i need to convert \r\n to \n (LF) and it works

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
suluxan referenced this issue in pughlab/matchminer-api-v1 Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests