debug时 import fastNLP语句会报错
iamqiz opened this issue · 3 comments
iamqiz commented
debug下面python文件.在import 语句处设置断点
a=4
g=3
import fastNLP
from fastNLP import Trainer
from fastNLP import Evaluator
from fastNLP import Accuracy
c=4
debug运行经过这个import语句时 会报错: 大意是cv2 模块找不到 ; 直接run是没问题,但debug有问题
我也不确定这是wsl2的问题还是ide的问题, 还是fastnlp的问题, 但感觉是fastnlp的问题,因为debug运行经过torch 语句时不会出错,
无论是pycharm还是vscode 都会有这个问题
pycharm里表现为:
Remote file /tmp/pycharm_project_930/ is mapped to the local path F:\WORK_PY\tmp_dir\dsa\ and can't be found. You can continue debugging, but without the source. To fix that you can do one of the following:
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(sys), STORE_NAME(sys), LOAD_NAME(sys.path), LOAD_METHOD(insert), LOAD_CONST(0), LOAD_CONST('/home/wslmsi20/.vscode-server/extensions/ms-python.python-2022.18.2/pythonFiles/lib/python/debugpy/_vendored/pydevd'), CALL_METHOD{2}, POP_TOP, LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(pydevd), STORE_NAME(pydevd), LOAD_CONST('http_json'), LOAD_NAME(pydevd.PydevdCustomization), STORE_ATTR(DEFAULT_PROTOCOL), LOAD_NAME(pydevd.settrace), LOAD_CONST('127.0.0.1'), LOAD_CONST(37511), LOAD_CONST(False), LOAD_CONST(False), LOAD_CONST(True), LOAD_CONST(None), LOAD_CONST('4f1d0ca13c1325157c2952984fa7fa6b9809f7dc99e1f3a3d8c89b583ff08365'), LOAD_CONST('127.0.0.1'), LOAD_CONST('4f1d0ca13c1325157c2952984fa7fa6b9809f7dc99e1f3a3d8c89b583ff08365'), LOAD_CONST(True), LOAD_CONST(True), LOAD_CONST(37511), LOAD_CONST(8115), LOAD_CONST(False), LOAD_CONST(True), LOAD_CONST(('client', 'client-access-token', 'json-dap-http', 'multiprocess', 'port', 'ppid', 'server', 'skip-notify-stdin')), BUILD_CONST_KEY_MAP{8}, LOAD_CONST(('host', 'port', 'suspend', 'trace_only_current_thread', 'patch_multiprocessing', 'access_token', 'client_access_token', '__setup_holder__')), CALL_FUNCTION_KW{8}, POP_TOP, LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(cv2), STORE_NAME(cv2), return None
后来我就安装了CV2
pip3 uninstall opencv-python
问题就解决了,
但是我很好奇,这到底是为什么?
环境:
win10 wsl2
fastnlp 1.0.1
iamqiz commented
我知道原因了, fastNLP会导入paddle, paddle又会导入cv2 ,代码位于以下文件
paddle\dataset\image.py
它通过subprocess调用python 执行import cv2 , 直接运行没问题, 但是debug就有问题了
import_cv2_proc = subprocess.Popen(
[interpreter, "-c", "import cv2"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = import_cv2_proc.communicate()
retcode = import_cv2_proc.poll()
你们能复现吗?
iamqiz commented
paddle 里有人提了这个issue
debug 时会卡一下报 "no module named cv2" · Issue #44760 · PaddlePaddle/Paddle
PaddlePaddle/Paddle#44760
yhcc commented
感谢你的反馈,根据我们之前的经验,如果一个环境中同时安装了torch/paddle比较容易导致bug的出现~