很多小伙伴在使用jieba的paddle模式时遇到一个问题,那就是paddlepaddle-tiny安装不上,执行pip install paddlepaddle-tiny==1.6.1
会出现以下错误:
ERROR: Could not find a version that satisfies the requirement paddlepaddle-tiny==1.6.1 (from versions: none)
ERROR: No matching distribution found for paddlepaddle-tiny==1.6.1
我也遇到了这个莫名其妙的错误,竟然找不到paddlepaddle-tiny==1.6.1
?
(行文杂乱,解决方法直接看最后)
大名鼎鼎的paddlepaddle不会没有官方镜像吧,pypi上确实有,但是最新的版本还有2019年的:
可以看到,最新版本名字为paddlepaddle_tiny-1.6.1-cp37-cp37m-win_amd64.whl
那就还是轮子(wheel)不匹配的问题,通过pip debug --verbose
命令可以查看当前操作系统支持的标签,如下所示:
Compatible tags: 33
cp39-cp39-win_amd64
cp39-abi3-win_amd64
cp39-none-win_amd64
cp38-abi3-win_amd64
cp37-abi3-win_amd64
cp36-abi3-win_amd64
cp35-abi3-win_amd64
cp34-abi3-win_amd64
cp33-abi3-win_amd64
cp32-abi3-win_amd64
py39-none-win_amd64
py3-none-win_amd64
py38-none-win_amd64
py37-none-win_amd64
py36-none-win_amd64
py35-none-win_amd64
py34-none-win_amd64
py33-none-win_amd64
py32-none-win_amd64
py31-none-win_amd64
py30-none-win_amd64
cp39-none-any
py39-none-any
py3-none-any
py38-none-any
py37-none-any
py36-none-any
py35-none-any
py34-none-any
py33-none-any
py32-none-any
py31-none-any
py30-none-any
通过更改文件名的方式可以强制安装wheel,那么问题来了,我怎么才能知道这个wheel和我的环境到底匹不匹配呢?
轮子(wheel)是通过build
包构建打包生成的,那么这个wheel的文件名规则自然也在build包中,源码看不懂,但总可以在文档中发现蛛丝马迹(以下是pip的文档,链接pip_debug):
platform和python_version都好理解,那implementation又是什么,‘pp’、‘jy’、‘cp’、'ip’都是啥意思?
通过搜索引擎加文档,找到了答案,可以在本机上通过以下方式查看自己的python实现:
最后还剩下一个abi,api是python的接口,abi是c的接口,简单理解为c语言的接口吧,个人理解,感觉应该影响不大,应该从tag上看好多abi都是none,这意思应该是兼容吧?
解决
将文件名字改为paddlepaddle_tiny-1.6.1-cp37-abi3-win_amd64.whl(随便改一个abi,或者改为none),执行命令pip install paddlepaddle_tiny-1.6.1-cp37-abi3-win_amd64.whl
,安装成功!
(venv) PS D:\code\python_programs\newdemand> pip install .\paddlepaddle_tiny-1.6.1-cp37-abi3-win_amd64.whl
Processing d:\code\python_programs\newdemand\paddlepaddle_tiny-1.6.1-cp37-abi3-win_amd64.whl
Requirement already satisfied: decorator in d:\code\python_programs\newdemand\venv\lib\site-packages (from paddlepaddle-tiny==1.6.1) (5.1.1)
Collecting numpy>=1.12
Downloading numpy-1.23.4-cp39-cp39-win_amd64.whl (14.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.7/14.7 MB 22.8 kB/s eta 0:00:00
Collecting objgraph
Downloading objgraph-3.5.0-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: six in d:\code\python_programs\newdemand\venv\lib\site-packages (from paddlepaddle-tiny==1.6.1) (1.16.0)
Collecting graphviz
Downloading graphviz-0.20.1-py3-none-any.whl (47 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.0/47.0 kB 41.3 kB/s eta 0:00:00
Collecting protobuf>=3.1.0
Downloading protobuf-4.21.9-cp39-cp39-win_amd64.whl (525 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 525.5/525.5 kB 25.8 kB/s eta 0:00:00
Requirement already satisfied: requests>=2.0.0 in d:\code\python_programs\newdemand\venv\lib\site-packages (from paddlepaddle-tiny==1.6.1) (2.28.1)
Requirement already satisfied: certifi>=2017.4.17 in d:\code\python_programs\newdemand\venv\lib\site-packages (from requests>=2.0.0->paddlepaddle-tiny==1.6.1) (2022.9.24)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\code\python_programs\newdemand\venv\lib\site-packages (from requests>=2.0.0->paddlepaddle-tiny==1.6.1) (1.26.12)
Requirement already satisfied: charset-normalizer<3,>=2 in d:\code\python_programs\newdemand\venv\lib\site-packages (from requests>=2.0.0->paddlepaddle-tiny==1.6.1)
(2.1.1)
Requirement already satisfied: idna<4,>=2.5 in d:\code\python_programs\newdemand\venv\lib\site-packages (from requests>=2.0.0->paddlepaddle-tiny==1.6.1) (3.4)
Installing collected packages: protobuf, numpy, graphviz, objgraph, paddlepaddle-tiny
Successfully installed graphviz-0.20.1 numpy-1.23.4 objgraph-3.5.0 paddlepaddle-tiny-1.6.1 protobuf-4.21.9
但是paddle模式还是不能正常运行,根据我的尝试,还需要安装paddlepaddle,并调整protobuf的版本,我用的版本是:
paddlepaddle==2.3.2
protobuf==3.20.0
还要加上:
paddle.enable_static()
最后paddle模式成功运行!