今天在新的一台电脑上安装了pip。流程有点忘记了,在这里再次记录下来。
本教程基于python3.4,并且需要连接互联网,总共需要两步。
1、要安装pip,首先要安装setuptools,链接:https://pypi.python.org/pypi/setuptools#windows-powershell-3-or-later
右键点击 ez_setup.py 另存为,把ez_setup.py下载好。然后打开cmd, 把当前工作路径改为ez_setup.py所在路径,输入python ez_setup.py,即可自动安装好
TIP:如果输入python ez_setup.py后,显示找不到python,则应该把python.exe所在路径加入系统环境变量path中。
2、下载pip,链接:https://pypi.python.org/pypi/pip#downloads
选择pip-7.1.2.tar.gz (md5, pgp)
下载好后解压,打开cmd,把当前工作路径改为刚刚解压后的pip-7.1.2文件夹下,输入python setup.py install,即可安装好。
最后一步,把python根目录下的Scripts路径加入系统环境变量path中。因为安装setuptools后,安装的所有第三方库都在该路径下。我们刚刚安装的pip也在改路径下。
所以如果想安装新的第三方库,直接在cmd输入命令:pip install 第三方库名 就可以了。
Eg: pip install chardet
更新:遇到一次pip install error:
pip install -U pip Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine("''",))': /simple/pip/ Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine("''",))': /simple/pip/ Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine("''",))': /simple/pip/ Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine("''",))': /simple/pip/ Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine("''",))': /simple/pip/ Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages
解决方法:加sudo
sudo pip install -U pip
其他pip install error可能的解决方案:
换源(因为默认的pypi的源有时访问不到,或者太慢)
检查系统时间(如果有些package的发布时间比你的系统时间晚,那么可能安装不成功)