问题描述

在使用 python3.8 安装 paddle 以后,测试导入 paddle 报错。

创建环境并安装source activate paddle38pip install paddlepaddle-gpu -i https://pypi.tuna.tsinghua.edu.cn/simplepip install paddlehub -i https://pypi.tuna.tsinghua.edu.cn/simplepip install paddleocr -i https://pypi.tuna.tsinghua.edu.cn/simplepip install paddleclas -i https://pypi.tuna.tsinghua.edu.cn/simplepython>>> import paddleError:Cannotimportpaddlecorewhilethisfileexists:/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/fluid/libpaddle.sogrep: warning: GREP_OPTIONS is deprecated; please use an alias or scriptTraceback (most recent call last):File "", line 1, in <module>File"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/__init__.py", line 25, in <module>from .framework import monkey_patch_variableFile"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/framework/__init__.py", line 17, in <module>from . import random # noqa: F401File"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/framework/random.py", line 16, in <module>import paddle.fluid as fluidFile"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/fluid/__init__.py", line 36, in <module>from . import frameworkFile"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/fluid/framework.py", line 37, in <module>from . import coreFile"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/fluid/core.py", line 304, in <module>raise eFile"/root/anaconda3/envs/paddle38/lib/python3.8/site-packages/paddle/fluid/core.py", line 249, in <module>from . import libpaddleImportError: libcudart.so.10.2: cannot open shared object file: No such file ordirectory>>>

问题分析

查看很多资料,发现最大的可能性是安装依赖包时对应版本错误,显卡驱动不支持 cuda10.2 或者没有安装正确的驱动,我这里安装的驱动是 cuda11.7 和默认的驱动不匹配,所以需要重新安装。

解决方案

使用的 conda 安装 python3.8,通过指定版本和国内镜像进行安装

source activate paddle38conda install paddlepaddle-gpu==2.4.2 cudatoolkit=11.7 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge# 或者使用 pip 安装python -m pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html