如果在streamlit应用中,使用pytorch报了下面这个错误Tried to instantiate class '__path__._path', but it does not exist! Ensure that it is registered via torch::class_
The report indicates minor increases in key financial metrics with overall stability in the company's financial health.
2025-03-19 21:56:56.388 Examining the path of torch.classes raised:
Traceback (most recent call last):
File "/home/caser/miniconda3/envs/finance_agent/lib/python3.10/site-packages/streamlit/web/bootstrap.py", line 345, in run
if asyncio.get_running_loop().is_running():
RuntimeError: no running event loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/caser/miniconda3/envs/finance_agent/lib/python3.10/site-packages/streamlit/watcher/local_sources_watcher.py", line 217, in get_module_paths
potential_paths = extract_paths(module)
File "/home/caser/miniconda3/envs/finance_agent/lib/python3.10/site-packages/streamlit/watcher/local_sources_watcher.py", line 210, in <lambda>
lambda m: list(m.__path__._path),
File "/home/caser/miniconda3/envs/finance_agent/lib/python3.10/site-packages/torch/_classes.py", line 13, in __getattr__
proxy = torch._C._get_custom_class_python_wrapper(self.name, attr)
RuntimeError: Tried to instantiate class '__path__._path', but it does not exist! Ensure that it is registered via torch::class_
可以在代码中添加下列代码解决。
import os
import torch
torch.classes.__path__ = [os.path.join(torch.__path__[0], torch.classes.__file__)]