Python代码调试过程中可能遇到的报错合集(将持续更新)

1. 三维重建MVSNet代码调试

可能遇到的报错1

message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot 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).

报错1解决方法

报错1解决办法:在虚拟环境“You_env”中重新安装protobuf

pip install protobuf==3.20.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

可能遇到的报错2

self.num_batches_tracked = self.num_batches_tracked + 1 # type: ignore[has-type]
RuntimeError: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

报错2解决方法

问题参考详细见:pytorch算力报错讨论

报错2解决办法:在虚拟环境“You_env”中重新安装与当前显卡算力相匹配的环境依赖库

pip3 install torch torchvision torchaudio --force-reinstall  --extra-index-url https://download.pytorch.org/whl/cu111

注意,cu111根据你的cuda版本来设置,使用nvcc -V查看,如果显示11.4则使用cu114

2. ESPNetV2代码调试

可能遇到的报错3

rgb_img = rgb_img.resize(new_size, Image.ANTIALIAS)
AttributeError: module ‘PIL.Image’ has no attribute ‘ANTIALIAS’
在这里插入图片描述

报错3解决方法

Pillow版本不符合,Pillow-10.X 的版本已经弃用“Image.ANTIALIAS”,换用低版本的Pillow即可。

pip install Pillow==9.5.0

可能遇到的报错4(调试MMsegmentation)

assert (mmcv_min_version <= mmcv_version < mmcv_max_version),
AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4.
在这里插入图片描述

报错4解决方法

按照提示要求安装对应版本的mmcv

pip install "mmcv==2.0.0rc4"

在这里插入图片描述
可能遇到的报错5 (Conda环境错误问题)

问题描述:在激活了conda环境之后进行的pip安装,没能把所需的依赖库安装到当前已经激活的虚拟环境中。使用命令pip install show XXX查看对应的依赖库位置,大象并不在我指定的虚拟环境目录下,卸载此库发现此依赖库也不在指定的虚拟环境目录下,如下所示。
在这里插入图片描述

报错5解决方法

使用“conda”进行安装
在这里插入图片描述
再次查看,发现所需的依赖库已经在指定的虚拟环境目录下了。

在这里插入图片描述

可能遇到的报错6
问题描述:
使用mmsegmentation时无法恢复训练,原因是mmengine版本过高导致
更换MMengine版本时遇到报错
执行:mim install mmengine==0.10.2
在这里插入图片描述
from charset_normalizer.md import mess_ratio
File “charset_normalizer/md.py”, line 5, in
ImportError: cannot import name ‘COMMON_SAFE_ASCII_CHARACTERS’ from ‘charset_normalizer.constant’ (/home/ly/anaconda3/envs/openmmlab/lib/python3.8/site-packages/charset_normalizer/constant.py)

在这里插入图片描述
报错6解决方法

先升级:charset-normalizer

pip install --upgrade charset-normalizer

再执行命令:

mim install mmengine==0.10.2
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值