今天搭建服务,搭建完使用Python提示缺少redis模块。经过检查是pip源的问题。
对于Python开发用户来讲,PIP安装软件包是家常便饭。但国外的源下载速度实在太慢,浪费时间。而且经常出现下载后安装出错问题。所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成功率。
国内源:
新版ubuntu要求使用https源,要注意。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学 :https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban):https://pypi.douban.com/simple/
临时使用:
可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://mirrors.aliyun.com/pypi/simple/ redis
easy_install -i https://mirrors.aliyun.com/pypi/simple/ redis
顺便说说pip和easy_install的区别:
easy_install 和 pip的介绍:
easy_install和pip都是用来下载安装python的一个公共资源库PyPI的相关资源包的,pip是easy_install的改进版,提供更好的提示信息,删除package等功能,老版本的python只有easy_install,没有pip
easy_install打包和发布Python包
pip是包管理
安装easy_install的两种方式:
1、 源码安装setuptools
安装setuptools之后,easy_install就已经安装好了。
Setuptools下载地址:https://pypi.python.org/pypi/setuptools
Windows下可以直接运行.exe文件,linux下解压,python setup.py install
2、 通过引导程序ez_setup.py安装
引导程序会联网下载最新版本的setuptools,也可以用来更新本地的setuptools.
wget http://peak.telecommunity.com/dist/ez_setup.py
安装:python ez_setup.py
安装PIP的两种方式:
1、使用easy_install安装pip
Easy Install是一个带有setuptools的python模块。这也用于管理,下载,构建和安装python模块。
$ easy_install pip
2、使用Python脚本安装pip
同样,您也可以使用pip安装脚本。 使用wget或curl下载脚本,然后使用适当的python版本运行脚本,您需要安装该脚本。
$ curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py”
$ python get-pip.py
$ python3 get-pip.py # For specific python version
easy_install的用法:
1) 安装一个包
$ easy_install <package_name>
$ easy_install “<package_name>==<version>”
2) 升级一个包
$ easy_install -U “<package_name>>=<version>”
pip的用法:
1) 安装一个包
$ pip install <package_name>
$ pip install <package_name>==<version>
2) 升级一个包 (如果不提供version号,升级到最新版本)
$ pip install –upgrade <package_name>>=<version>
3)删除一个包
$ pip uninstall <package_name>