安装pip
转载请注明 来源:http://www.eword.name/
Author:eword
Email:eword@eword.name
安装pip
pip是常用的python包管理工具。
一、在系统自带的python2.7的路径下安装pip
在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装。
sudo easy_install pip
Searching for pip
Reading https://pypi.org/simple/pip/
Downloading https://files.pythonhosted.org/packages/5a/4a/39400ff9b36e719bdf8f31c99fe1fa7842a42fa77432e584f707a5080063/pip-20.2.2-py2.py3-none-any.whl#sha256=5244e51494f5d1dfbb89da492d4250cb07f9246644736d10ed6c45deb1a48500
Best match: pip 20.2.2
Processing pip-20.2.2-py2.py3-none-any.whl
Installing pip-20.2.2-py2.py3-none-any.whl to /Library/Python/2.7/site-packages
Adding pip 20.2.2 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3.8 script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-20.2.2-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
二、在python3.x的路径下安装pip
curl https://bootstrap.pypa.io/get-pip.py | python3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1840k 100 1840k 0 0 45105 0 0:00:41 0:00:41 --:--:-- 267k
Collecting pip
Downloading pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 55 kB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 19.1.1
Uninstalling pip-19.1.1:
Successfully uninstalled pip-19.1.1
Successfully installed pip-20.2.2
三、安装验证
pip --version
pip 20.2.2 from /Library/Python/2.7/site-packages/pip-20.2.2-py2.7.egg/pip (python 2.7)
pip3 --version
pip 19.0.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
四、更新pip
pip install --upgrade pip
pip3 install --upgrade pip
如果升级失败,使用以下命令升级
python -m pip install -U --force-reinstall pip
五、卸载pip
python -m pip uninstall pip
python3 -m pip uninstall pip
六、安装第三方包
pip install 包名
七、卸载第三方包
pip uninstall 包名
八、查询已安装的包
pip list
九、更换国内镜像源
# linux下,修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# 团队私有源(VPN下):https://dev.bolangit.cn/nexus/repository/pypi-public/simple/
# windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
十、例子:安装numpy
下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
执行:numpy包名称要加英文双引号。
pip install “[numpy包名称] ”
10.1、另一种方式安装包
setup.py https://pypi.python.org/pypi
-
先下载你要安装的包,并解压到磁盘下;
-
进入到该文件的setup.py 目录下 ,打开cmd,并切换到该目录下;
-
先执行 python setup.py build
-
然后执行 python setup.py install