File c:\users\ljimmy\appdata\local\programs\python\python38\lib\site-packages\werkzeug\_reloader.py:315, in WatchdogReloaderLoop.__init__(self, *args, **kwargs) 313 from watchdog.observers import Observer 314 from watchdog.events import PatternMatchingEventHandler --> 315 from watchdog.events import EVENT_TYPE_OPENED 316 from watchdog.events import FileModifiedEvent 318 super().__init__(*args, **kwargs) ImportError: cannot import name 'EVENT_TYPE_OPENED' from 'watchdog.events' (c:\users\ljimmy\appdata\local\programs\python\python38\lib\site-packages\watchdog\events.py)
时间: 2023-07-06 09:37:32 浏览: 180
这个错误是由于您正在使用的 watchdog 库版本过低导致的。EVENT_TYPE_OPENED 是 watchdog 0.10.0 引入的,如果您的版本低于该版本,将无法找到该常量。请尝试升级 watchdog 库到最新版本,或者使用以下代码替换您的代码以使用旧版 watchdog:
```python
import watchdog.events
if not hasattr(watchdog.events, "EVENT_TYPE_OPENED"):
watchdog.events.EVENT_TYPE_OPENED = 'created'
```
相关问题
File c:\users\ljimmy\appdata\local\programs\python\python38\lib\site-packages\werkzeug\_reloader.py:440, in run_with_reloader(main_func, extra_files, exclude_patterns, interval, reloader_type) 437 import signal 439 signal.signal(signal.SIGTERM, lambda *args: sys.exit(0)) --> 440 reloader = reloader_loops[reloader_type]( 441 extra_files=extra_files, exclude_patterns=exclude_patterns, interval=interval 442 ) 444 try: 445 if os.environ.get("WERKZEUG_RUN_MAIN") == "true": File c:\users\ljimmy\appdata\local\programs\python\python38\lib\site-packages\werkzeug\_reloader.py:315, in WatchdogReloaderLoop.__init__(self, *args, **kwargs) 313 from watchdog.observers import Observer 314 from watchdog.events import PatternMatchingEventHandler --> 315 from watchdog.events import EVENT_TYPE_OPENED 316 from watchdog.events import FileModifiedEvent 318 super().__init__(*args, **kwargs) ImportError: cannot import name 'EVENT_TYPE_OPENED' from 'watchdog.events' (c:\users\ljimmy\appdata\local\programs\python\python38\lib\site-packages\watchdog\events.py)
这个错误是因为 Watchdog 的版本问题导致的。Watchdog 从版本 2.1.0 开始不再支持 `EVENT_TYPE_OPENED` 常量,而你的 Flask 应用程序或其他依赖项需要这个常量。
解决这个问题的方法之一是降级 Watchdog 的版本到 2.0.2。你可以使用以下命令来降级 Watchdog:
```
pip install watchdog==2.0.2
```
如果你的项目中还有其他依赖项,可能需要执行类似的操作来解决版本冲突问题。
另外,当你使用 Watchdog 2.0.2 时,你可能需要在代码中将 `EVENT_TYPE_OPENED` 改为 `EVENT_TYPE_CREATED`,因为这个常量的名称在 Watchdog 2.1.0 中被更改了。
Traceback (most recent call last): File "D:/PyCharm 2021/新建文件夹/数据转成可视化.py", line 105, in <module> map_1.render("全国疫情分布图.html") File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pyecharts\charts\base.py", line 92, in render self._prepare_render() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pyecharts\charts\base.py", line 116, in _prepare_render self.json_contents = self.dump_options() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pyecharts\charts\base.py", line 77, in dump_options json.dumps(self.get_options(), indent=4, default=default, ignore_nan=True) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\__init__.py", line 381, in dumps return cls( File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 300, in encode chunks = list(chunks) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 714, in _iterencode for chunk in _iterencode_dict(o, _current_indent_level): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 668, in _iterencode_dict for chunk in chunks: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 735, in _iterencode for chunk in _iterencode(o, _current_indent_level): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 714, in _iterencode for chunk in _iterencode_dict(o, _current_indent_level): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 668, in _iterencode_dict for chunk in chunks: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 544, in _iterencode_list for chunk in chunks: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 620, in _iterencode_dict key = _stringify_key(key) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\simplejson\encoder.py", line 580, in _stringify_key raise TypeError('keys must be str, int, float, bool or None, ' TypeError: keys must be str, int, float, bool or None, not builtin_function_or_method
这个错误是由于在使用pyecharts库时,传入了一个非法的键(key),导致无法将其转换为JSON格式。根据错误信息,这个键的类型是内置函数或方法(builtin_function_or_method),而JSON只支持字符串(str)、整数(int)、浮点数(float)、布尔值(bool)或None类型的键。
要解决这个问题,你需要检查代码中使用pyecharts库的部分,确认传入的键是合法的类型。如果有使用内置函数或方法作为键的情况,需要修改代码,将其转换为合法类型的键,例如字符串。
如果你无法确定出现问题的具体代码,请提供更多关于你使用pyecharts库的代码片段,我可以帮你进一步分析和解决问题。
阅读全文