"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

Asked By: brian valladares

||

Answers:

Try to do the following:

pip install --upgrade watchdog
Answered By: Gbuntu

I was running a similar command on jupyter and got the same error… just change degug to False and no worries

Answered By: Zowye

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.

Answered By: yoniLavi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.