Python开发:部分第三方库无法在线安装解决方法

一、问题如下:

  1、截图:

  

  2、错误信息:  

  Could not find a version that satisfies the requirement re (from versions: )

  No matching distribution found for re

  3、翻译:

  找不到满足re要求的版本(来自版本: ) 找不到re的匹配分布

二、解决方法:

  1、采用国内镜像则能够提高安装成功率并提速:

        
http://mirrors.aliyun.com/pypi/simple/   阿里云
https://pypi.mirrors.ustc.edu.cn/simple/   中国科技大学
http://pypi.douban.com/simple/   豆瓣
https://pypi.tuna.tsinghua.edu.cn/simple/   清华大学
 

  使用方法:

         
pip3 install -i http://pypi.tuna.tsinghua.edu.cn/simple re
 

  可能会出现如下问题:

  

  The repository located at pypi.tuna.tsinghua.edu.cn is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.tuna.tsinghua.edu.cn'.

  Could not find a version that satisfies the requirement re (from versions: )
  No matching distribution found for re

  linux 系统:

  在~/.pip/pip.conf (若没有此文件自行创建文件夹要加“.”,表示是隐藏文件夹)中设置以下内容:

         
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
 

  Windows系统:

  直接在user目录中创建一个pip目录,如:C:\Users\lenovo\pip,新建文件pip.ini,设置以下内容:

        
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
 

  2、在网站上下载第三方库的离线包,离线安装:

  网上收集的集合网站:

    LINUX(主要提供Linux版本的后缀是".whl"和“.tar.gz”):

      https://pypi.org/

    Windows(主要提供Windows版本的后缀是".whl"):

      https://www.lfd.uci.edu/~gohlke/pythonlibs/#tensorflow

      https://pypi.org/simple/

  python的离线安装,有时候由于不同模块有很多依赖包,所以很容易出错,在线安装会自动安装依赖包,所以一般不会出现安装问题。

  离线安装方法,".whl"文件安装如下:

  此处以ujson为例:
    linux版本的安装(默认文件在当前目录下)

         
pip3 install ujson的whl文件名
 

    我没有linux版本,这里只列一下代码。

  Windows版本的安装(默认文件在当前目录下)

         
pip3 install ujson‑1.35‑cp36‑cp36m‑win_amd64.whl
 

  

  安装时又出现了问题:

  

  ujson-1.35-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.

  意思就是说whl名的命名不符合它给的规范

  在python中使用以下命令:

  32位:

         
import pip
print(pip.pep425tags.get_supported())

  

 

  64位:

         
import pip._internal
print(pip._internal.pep425tags.get_supported())
 

  结果如下:

    

  支持里有个:('cp36', 'cp36m', 'win32')
  下的whl名字是:ujson-1.35-cp36-cp36m-win_amd64.whl,这是无法安装的,我改为:ujson-1.35-cp36-cp36m-win32.whl,就好了。如果是python2.7的,很可能库里存在兼容性问题。

  将下载的文件重命名为:

  

  之后就是安装成功

   

  可以看到在自己python路径下的Lib\site-packages文件夹下,看到ujson文件夹已经存在,到此安装完毕:

  

  推荐使用离线的方式,在线的不怎么靠谱,毕竟是国外网站,有时候一直连不上也是常事。

猜你喜欢

转载自www.cnblogs.com/guobin-/p/10688738.html
今日推荐