[python] pip安装国外软件库(包)失败,解决方案

第一种方法:先直接下载软件库,通过本机安装

1.打开 https://www.lfd.uci.edu/~gohlke/pythonlibs网站

2.搜索需要的 软件库

3.找到对应自己系统的版本并下载,cp后面的数字时python的版本,如cp36代表python3.6版本,WIN后面的数字32/64表示32或者64位系统;

4.下载后,使用pip install +路径文件名安装,例如:

pip install c:\pandas‑0.23.4‑cp36‑cp36m‑win_amd64.whl 

第二种方法:PyPI使用国内源

国内的pip源,如下:

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 

豆瓣(douban) http://pypi.douban.com/simple/ 

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

使用方法很简单,直接 -i 加 url 即可!

pip install web.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

如果想配置成默认的源,方法如下:

需要创建或修改配置文件(一般都是创建),

linux的文件在~/.pip/pip.conf,

windows在%HOMEPATH%\pip\pip.ini),

修改内容为:

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

 
这样在使用pip来安装时,会默认调用该镜像。

临时使用其他源安装软件包的python脚本如下:

#!/usr/bin/python
 
import os
 
package = raw_input("Please input the package which you want to install!\n")
command = "pip install %s -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn" % package
os.system(command)

也可以使用读入文件进行安装

https://www.cnblogs.com/sunnydou/p/5801760.html

猜你喜欢

转载自www.cnblogs.com/lyggqm/p/12741553.html