文章目录

0 背景

最近在做文章高频词频统计,用到了​​jieba​​​的库,里面有一个paddle模式【利用PaddlePaddle深度学习框架,训练序列标注(双向GRU)网络模型实现分词】,但是使用​​jieba.enable_paddle()​​开启模式的时候,报错了。

Import paddle error, please use command to install: pip install paddlepaddle-tiny==1.6.1.Now

在网上尝试了各种解决方法,都没有用。

pip3 install paddlepaddle
pip3 install paddlepaddle==1.8.5

最后找到了pypi官网,也就是python包官网,找到了对应的包,解决了问题。

1 解决

cpu:
python2:

python -m pip install paddlepaddle

python3:

python3 -m pip install paddlepaddle

gpu-cuda10.2:
python2:

python -m pip install paddlepaddle-gpu

python3:

python3 -m pip install paddlepaddle-gpu

gpu-cuda9、10.0、10.1、11:
We only release paddlepaddle-gpu cuda10.2 on pypi.

If you want to install paddlepaddle-gpu with cuda version of 9.0 ,10.0 ,10.1 ,or 11.0, commands to install are on our website: Installation Document

2 安装好的检查

import paddle
paddle.fluid.install_check.run_check()

Import paddle error, please use command to install: pip install paddlepaddle-tiny==1.6.1.Now_paddle

另一种引入头文件的方法为:

使用​​jieba.enable_paddle()​​​【0.40版之后开始支持,早期版本不支持】。​​jieba.enable_paddle()​​的源代码为:

def enable_paddle():
try:
import paddle
except ImportError:
default_logger.debug("Installing paddle-tiny, please wait a minute......")
os.system("pip install paddlepaddle-tiny")
try:
import paddle
except ImportError:
default_logger.debug(
"Import paddle error, please use command to install: pip install paddlepaddle-tiny==1.6.1."
"Now, back to jieba basic cut......")
if paddle.__version__ < '1.6.1':
default_logger.debug("Find your own paddle version doesn't satisfy the minimum requirement (1.6.1), "
"please install paddle tiny by 'pip install --upgrade paddlepaddle-tiny', "
"or upgrade paddle full version by "
"'pip install --upgrade paddlepaddle (-gpu for GPU version)' ")
else:
try:
import jieba.lac_small.predict as predict
default_logger.debug("Paddle enabled successfully......")
check_paddle_install['is_paddle_installed'] = True
except ImportError:
default_logger.debug("Import error, cannot find paddle.fluid and jieba.lac_small.predict module. "
"Now, back to jieba basic cut......")

3 附带

对应的​​包官网地址​

4 另一种解决方法