"cannot import name 'EVENT_TYPE_OPENED' from 'watchdog.events' "
Question:
I’m trying to make a REST api (begginer) but when i tried to initialize the server from this code:
from flask import Flask
app = Flask(__name__)
if __name__=='__main__':
app.run(debug=True, port=4000)
i get this error in the prompt:
from watchdog.events import EVENT_TYPE_OPENED
ImportError: cannot import name 'EVENT_TYPE_OPENED' from 'watchdog.events'
(C: ********* PythonPython310libsite-packageswatchdogevents.py)
I’m expecting something like this (Min 8:27):
https://www.youtube.com/watch?v=GMppyAPbLYk&ab_channel=TechWithTim
Answers:
Try to do the following:
pip install --upgrade watchdog
I was running a similar command on jupyter and got the same error… just change degug to False and no worries
Following up on @Gbuntu’s answer, the issue is likely that for some reason you’re running an outdated version of watchdog.
After a bit of code archeology, I found that the support for FileOpenedEvent
was added in version 2.3.0, with the particular event constant EVENT_TYPE_OPENED
added in Pull Request #941.
If you prefer to set your pip install
(or requirements.txt
) to specific versions rather than just --upgrade
, I would recommend either watchdog~=2.3
, or better yet watchdog~=3.0
.
I’m trying to make a REST api (begginer) but when i tried to initialize the server from this code:
from flask import Flask
app = Flask(__name__)
if __name__=='__main__':
app.run(debug=True, port=4000)
i get this error in the prompt:
from watchdog.events import EVENT_TYPE_OPENED
ImportError: cannot import name 'EVENT_TYPE_OPENED' from 'watchdog.events'
(C: ********* PythonPython310libsite-packageswatchdogevents.py)
I’m expecting something like this (Min 8:27):
https://www.youtube.com/watch?v=GMppyAPbLYk&ab_channel=TechWithTim
Try to do the following:
pip install --upgrade watchdog
I was running a similar command on jupyter and got the same error… just change degug to False and no worries
Following up on @Gbuntu’s answer, the issue is likely that for some reason you’re running an outdated version of watchdog.
After a bit of code archeology, I found that the support for FileOpenedEvent
was added in version 2.3.0, with the particular event constant EVENT_TYPE_OPENED
added in Pull Request #941.
If you prefer to set your pip install
(or requirements.txt
) to specific versions rather than just --upgrade
, I would recommend either watchdog~=2.3
, or better yet watchdog~=3.0
.