pip最新源总结及pip常见问题解决方法(亲测有效)

一、简介

本文主要整理了pip常用的源地址以及在使用pip过程中报错的解决方法。
1 、模块缺少错误
2、 下载模块过程网速较慢中止
3、 源中无该模块
4、 更换不同源一直没有该模块

二、常用源总结

//阿里云
https://mirrors.aliyun.com/pypi/simple/ 
//中国科技大学
https://pypi.mirrors.ustc.edu.cn/simple/ 

//豆瓣(douban)
https://pypi.douban.com/simple/ 
//清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/ 
//中国科学技术大学
https://pypi.mirrors.ustc.edu.cn/simple/
//官方源
https://pypi.python.org/simple

三、更换源方式

3.1 临时使用方式:

pip install scrapy -i  http://mirrors.aliyun.com/pypi/simple/

3.2 永久修改源地址:

vim  ~/.pip/pip.conf   // (没有就创建一个), 内容如下:

[global]
index-url =  https://pypi.douban.com/simple/ 

2、命令设置源地址:

pip config set global.index-url  http://mirrors.aliyun.com/pypi/simple/ 

四、常见问题处理

4.1 模块缺少错误

Traceback (most recent call last):
File "fwpkg.py", line 4, in <module>
from Crypto.Hash import SHA256
ImportError: No module named Crypto.Hash
make: *** [Makefile:50:loader] 错误 1
//解决方法:
pip install pycrypto

4.2 下载模块过程网速较慢中止

在这里插入图片描述

//解决方法:更换其他源,个人喜欢用豆瓣源,感觉速度比较快
pip install pycrypto  -i http://pypi.douban.com/simple/  

若报错为该源未添加信任,追加–trusted-host pypi.douban.com即可:

root@VirtualBox:/# pip install pycrypto  -i http://pypi.douban.com/simple/ 
Looking in indexes: http://pypi.douban.com/simple/
WARNING: The repository located at pypi.douban.com 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.douban.com'.
//解决方法:
root@VirtualBox:/# pip install pycrypto  -i http://pypi.douban.com/simple/  --trusted-host pypi.douban.com

4.3 源中无该模块

root@VirtualBox:/# pip install cStringIO
ERROR: Could not find a version that satisfies the requirement cStringIO (from versions: none)
ERROR: No matching distribution found for cStringIO
解决方法:可以通过pip list查看该源下有的模块,若没有则更换其他源 

4.4 更换不同源一直没有该模块

考虑是否为python版本问题,本人遇到过用python3的版本一直没有cStringIO模块,因为默认用的python3的版本,此时可以更改默认使用的python版本,命令如下:

//创建/usr/bin/python软连接指向/usr/bin/python2.7:
ln -sf /usr/bin/python2.7 /usr/bin/python

猜你喜欢

转载自blog.csdn.net/Luckiers/article/details/126429598