问题描述
使用LAC(https://github.com/baidu/lac/blob/master/README.md)时,使用如下指令安装lac:
pip install lac
执行如下代码:
from LAC import LAC
报错:
Error: Can not import paddle core while this file exists: /root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/libpaddle.so
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/LAC/__init__.py", line 23, in <module>
from .lac import LAC
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/LAC/lac.py", line 28, in <module>
import paddle.fluid as fluid
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/__init__.py", line 31, in <module>
from .framework import monkey_patch_variable
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/framework/__init__.py", line 17, in <module>
from . import random # noqa: F401
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/framework/random.py", line 17, in <module>
from paddle import fluid
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/__init__.py", line 36, in <module>
from . import framework
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/framework.py", line 35, in <module>
from . import core
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/core.py", line 356, in <module>
raise e
File "/root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/core.py", line 269, in <module>
from . import libpaddle
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /root/miniconda3/envs/root/lib/python3.8/site-packages/paddle/fluid/libpaddle.so)
解决方法
该报错的原因为Pytorch与LAC冲突。只需要先import LAC,后import torch,即可解决该问题。
这里做一个测试,在python脚本中直接先导入LAC、后导入torch,不报错:
在python脚本中直接先导入torch、后导入LAC,报错: