cannot import name 'str_key' from 'utils' (C:\Users\19018\anaconda3\envs\syj1\lib\site-packages\utils\__init__.py)
时间: 2023-11-12 18:06:28 浏览: 161
这个错误提示表明在'C:\Users\19018\anaconda3\envs\syj1\lib\site-packages\utils\__init__.py'文件中无法导入名为'str_key'的函数。这可能是因为该函数在该文件中不存在或者该文件中的其他代码存在错误。您可以检查该文件中是否存在该函数,或者尝试使用其他版本的utils库。
相关问题
RuntimeError: Could not export Python function call 'F'. Remove calls to Python functions before export. Did you forget to add @script or @script_method annotation? If this is a nn.ModuleList, add it to __constants__: E:\bolang\yolov7-coupling\utils\activations.py(65): forward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(887): _call_impl E:\bolang\yolov7-coupling\models\common.py(112): fuseforward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(887): _call_impl E:\bolang\yolov7-coupling\models\yolo.py(744): forward_once E:\bolang\yolov7-coupling\models\yolo.py(707): forward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\nn\modules\module.py(887): _call_impl E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\jit\_trace.py(934): trace_module E:\anaconda\envs\pytorch-1.8.1\lib\site-packages\torch\jit\_trace.py(733): trace E:\bolang\yolov7-coupling\utils\torch_utils.py(363): __init__ E:\bolang\yolov7-coupling\detect.py(39): detect E:\bolang\yolov7-coupling\detect.py(196): <module>
这个错误是由于在导出模型时出现了问题。错误信息中提到了一个名为'F'的 Python 函数调用,但没有添加 `@script` 或 `@script_method` 注释。如果这是一个 `nn.ModuleList`,请将其添加到 `__constants__` 中。请检查您的代码中与这些部分相关的部分,并确保按照 PyTorch 的导出要求进行操作。
D:\anaconda\envs\pytorch\python.exe C:\Users\23896\Desktop\bev-lane-det_dachaung-master\tools\train_openlane.py Traceback (most recent call last): File "C:\Users\23896\Desktop\bev-lane-det_dachaung-master\tools\train_openlane.py", line 18, in <module> from torch.utils.tensorboard import SummaryWriter File "D:\anaconda\envs\pytorch\lib\site-packages\torch\utils\tensorboard\__init__.py", line 13, in <module> from .writer import FileWriter, SummaryWriter # noqa: F401 File "D:\anaconda\envs\pytorch\lib\site-packages\torch\utils\tensorboard\writer.py", line 9, in <module> from tensorboard.compat.proto.event_pb2 import SessionLog File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\event_pb2.py", line 17, in <module> from tensorboard.compat.proto import summary_pb2 as tensorboard_dot_compat_dot_proto_dot_summary__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\summary_pb2.py", line 17, in <module> from tensorboard.compat.proto import tensor_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\tensor_pb2.py", line 16, in <module> from tensorboard.compat.proto import resource_handle_pb2 as tensorboard_dot_compat_dot_proto_dot_resource__handle__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\resource_handle_pb2.py", line 16, in <module> from tensorboard.compat.proto import tensor_shape_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__shape__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\tensor_shape_pb2.py", line 36, in <module> _descriptor.FieldDescriptor( File "D:\anaconda\envs\pytorch\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__ _message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
这个错误提示表明在导入 `torch.utils.tensorboard` 模块时出现了问题,具体是由于 `google.protobuf` 模块的版本不兼容导致的。错误信息还提到了一些可能的解决方法。
要解决这个问题,你可以尝试以下几个步骤:
1. 首先,尝试升级 `google.protobuf` 模块。可以使用以下命令来升级:
```
pip install --upgrade protobuf
```
2. 如果升级 `google.protobuf` 后问题仍然存在,可以尝试降级 `protobuf` 包的版本。根据错误信息所述,可以尝试将 `protobuf` 降级到 3.20.x 或更低的版本:
```
pip install protobuf==3.20.0
```
3. 如果上述步骤都没有解决问题,可以尝试设置环境变量 `PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION` 为 `python`,但这会导致纯Python解析,速度较慢:
```
set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
```
请注意,在尝试这些解决方法之前,请确保你的环境中已经安装了最新版本的 `pip` 和 `setuptools`。
如果问题仍然存在,请提供关于你的环境和依赖项的更多详细信息,以便我能够更好地帮助你解决问题。
阅读全文