pip是python的包管理工具,python2.7/python3.4以上的版本都已經集成了該工具,我們可以用
pip --version
命令確認是否安裝,如果未安裝pip的,請往下看,
下載
進入https://pypi.org/project/pip/選擇紅框中的檔案下載
圖
windows下安裝
下載完成后解壓得到

我們用CMD進入該目錄下,輸入python setup.py install命令進行安裝

碼字不易廢話兩句:有需要python學習資料的或者有技術問題交流 “點擊”即可
如果是第一次安裝,我們還需要配置環境變數,如下圖


這樣,環境變數就配置好了,
配置完成后,在cmd中輸入pip確認安裝情況,
Linux下安裝
tar -xzvf pip-20.2.4.tar.gz # 解壓
cd pip-20.2.4 # 進入解壓檔案
python setup.py install # 安裝
pip的更新
python -m pip install --upgrade pip
安裝包
pip install 安裝包名
安裝指定版本的包
pip install 包名==版本號
例如我們要安裝Django的1.8版本
pip install Django==1.8
更新包
pip install --upgrade 要更新的包名
詢可更新的包
pip list --outdated

批量更新包
(1)利用pip-review進行包的批量更新
pip install pip-review
pip-review --local --interactive(2
(2)撰寫如下代碼進行批量更新
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pip
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call
for dist in get_installed_distributions():
print(dist)
if not 'pip' in str(dist):
call('pip3 install --upgrade %s -i https://pypi.tuna.tsinghua.edu.cn/simple' % dist.project_name, shell=True)
卸載包
pip uninstall 要卸載的包名
pip在國內的下載速度非常不理想,所以我們要借助國內的鏡像源來安裝需要的包
臨時使用
pip安裝包的時候加引數-i 鏡像源地址,例如
pip install bs4 -i https://pypi.tuna.tsinghua.edu.cn/simple
這樣就會從清華的鏡像源站安裝bs4庫
其他常用的鏡像源地址:
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
4.2 永久更改
linux
修改~/.pip/pip.conf (沒有就創建一個檔案夾及檔案,檔案夾要加“.”,表示是隱藏檔案夾),檔案內容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = mirrors.aliyun.com
windows
在用戶目錄下創建pip檔案夾,再在檔案夾中創建pip.ini組態檔,填寫一樣的內容

pip引數決議
Commands:
install 安裝包.
uninstall 卸載包.
freeze 按著一定格式輸出已安裝包串列
list 列出已安裝包.
show 顯示包詳細資訊.
search 搜索包,類似yum里的search.
wheel Buildwheelsfromyourrequirements.
zip 不推薦.Zipindividualpackages.
unzip 不推薦.Unzipindividualpackages.
bundle 不推薦.Createpybundles.
help 當前幫助.
GeneralOptions:
-h,--help 顯示幫助.
-v,--verbose 更多的輸出,最多可以使用3次
-V,--version 現實版本資訊然后退出.
-q,--quiet 最少的輸出.
--log-file<path> 覆寫的方式記錄verbose錯誤日志,默認檔案:/root/.pip/pip.log
--log<path> 不覆寫記錄verbose輸出的日志.
--proxy<proxy> Specifyaproxyintheform[user:passwd@]proxy.server:port.
--timeout<sec> 連接超時時間(默認15秒).
--exists-action<action> Defaultactionwhenapathalreadyexists:(s)witch,(i)gnore,(w)ipe,(b)ackup.
--cert<path> 證書.
以上就是小編今天為大家帶來的內容,小編本身就是一名python開發工程師,我自己花了三天時間整理了一套python學習教程,從最基礎的python腳本到web開發,爬蟲,資料分析,資料可視化,機器學習,等,這些資料有想要的小伙伴 " 點擊 " 即可領取
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/218848.html
標籤:其他
上一篇:shell腳本案例(初級)
下一篇:Apache網頁優化
