有时候用pip 安装python 库时会找不到合适的安装包文件,这时可以尝试用一些非官方的安装包。
这里有一个非官方安装包的资源站点,提供了windows下的 whl 安装文件
接下来通过一个例子说明具体用法。
准备在python3.7上安装 PyUserInput。这个库可以用来模拟键盘及鼠标的操作。
先尝试用pip 安装
D:\Python37\Scripts>pip install PyUserInput
Collecting PyUserInput
Downloading https://files.pythonhosted.org/packages/d0/09/17fe0b16c7eeb52d6c14e904596ddde82503aeee268330120b595bf22d7b/PyUserInput-0.1.11.tar.gz
Collecting pyHook (from PyUserInput)
Could not find a version that satisfies the requirement pyHook (from PyUserInput) (from versions: )
No matching distribution found for pyHook (from PyUserInput)
从错误提示可以发现,无法自动安装依赖项 pyHook。
于是打开上面介绍的资源站点
按下Ctrl+F ,在页面上查找 pyhook
找到后点击跳转到下载链接
如上图红色标记所示,我的电脑是64位系统,找到与我的电脑匹配的 pyHook?1.5.1?cp37?cp37m?win_amd64.whl,并下载,保存到python3.7 安装文件夹 Scripts 目录中。
执行下面的语句安装这个下载得到的whl文件:
pip install pyHook-1.5.1-cp37-cp37m-win_amd64.whl
运行提示如下:
D:\Python37\Scripts>pip install pyHook-1.5.1-cp37-cp37m-win_amd64.whl
Processing d:\python37\scripts\pyhook-1.5.1-cp37-cp37m-win_amd64.whl
Installing collected packages: pyHook
Successfully installed pyHook-1.5.1
说明pyHook已经安装好了,接下来再次执行 pip install PyUserInput ,看看是否还有问题
D:\Python37\Scripts>pip install PyUserInput
Collecting PyUserInput
Using cached https://files.pythonhosted.org/packages/d0/09/17fe0b16c7eeb52d6c14e904596ddde82503aeee268330120b595bf22d7b/PyUserInput-0.1.11.tar.gz
Requirement already satisfied: pyHook in d:\python37\lib\site-packages (from PyUserInput) (1.5.1)
Requirement already satisfied: pywin32 in d:\python37\lib\site-packages (from PyUserInput) (224)
Installing collected packages: PyUserInput
Running setup.py install for PyUserInput ... done
Successfully installed PyUserInput-0.1.11
安装完成,一切OK