pip 常用命令
1 檢視幫助文件
pip --help
Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. config Manage localand global configuration. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show helpfor commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). ··· ···
使用時,輸入pip <command> [options]
形式的指令,即可執行相應的命令,並且,command 和 options 可以任意組合
pip install --help
pip uninstall --help
Usage: pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... pip install [options] [-e] <vcs project url> ... pip install [options] [-e] <local project path> ... pip install [options] <archive url/path> ... Description: Install packages from: - PyPI (and other indexes) using requirement specifiers. - VCS project urls. - Local project directories. - Local or remote source archives. pip also supports installing from "requirements files", which provide an easy way to specify a whole environment to be installed. Install Options: -r, --requirement <file> Install from the given requirements file. This option can be used multiple times. -c, --constraint <file> Constrain versions using the given constraints file. This option can be used multiple times. --no-deps Don't install package dependencies.
2 install
使用 install 命令用於安裝軟體包。
pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... pip install [options] [-e] <vcs project url> ... pip install [options] [-e] <local project path> ... pip install [options] <archive url/path> ...
第一種: pip install [options] [package-index-options]
這種方法用於從 Python 包索引網站上直接下載並安裝軟體包,預設使用PyPI上的包索引。安裝時,只需提供包名即可,下載安裝會自動進行。
pip install numpy
通過使用==, >=, <=, >, < 來指定一個版本號,未指定版本號,將預設下載最新版本。
pip install SomePackage # 最新版本 pip install SomePackage==1.0.4 # 指定版本 pip install 'SomePackage>=1.0.4' # 最小版本
也可從其他索引安裝,例如,換成豆瓣的映象。
pip install --index-url https://pypi.douban.com/simple SomeProject pip install -i https://pypi.douban.com/simple SomeProject # --index-url 可簡寫為 -i
除了PyPI之外,在安裝期間搜尋其他索引
pip install --extra-index-url https://pypi.douban.com/simple SomeProject
第二種:pip install [options] -r [package-index-options]
通過 requirements 檔案批量安裝 軟體包,指令如下
pip install -r requirements.txt
在 requirements.txt 檔案中,同樣可指定版本,預設安裝最新版 requirements.txt內容格式為:
Django==1.5.4
MySQL-python>=1.2.3
第三種: pip install [options] [-e]
從VCS安裝,以“可編輯”模式從VCS安裝專案。有關語法的完整細分,請參閱有關VCS支援的部分。
pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject # 從 git 安裝 pip install -e hg+https://hg.repo/some_pkg#egg=SomeProject # 從 mercurial 安裝 pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject # 從 svn 安裝 pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomeProject # 安裝某一分支 branch
第四種:pip install [options] [-e]
此種方式用於安裝本地安裝包,例如
pip install ./downloads/SomeProject-1.0.4.tar.gz
從包含安裝包的本地目錄搜尋並安裝(並且不檢查PyPI索引)
pip install --no-index --find-links=file:///local/dir/ SomeProject pip install --no-index --find-links=/local/dir/ SomeProject pip install --no-index --find-links=relative/dir/ SomeProject
第五種:pip install [options]
從指定的 url 地址下載包並安裝。
另外,列舉幾個常用的 install 選項。
更新安裝包
pip install --upgrade SomeProject pip isstall -U SomeProject # --upgrade 可簡寫為 -U pip install --upgrade pip # pip升級自己
安裝到使用者目錄
pip install numpy --user # numpy包會安裝到使用者目錄下,而非系統目錄
忽略是否已安裝
pip install numpy --ignore-installed # 忽略 numpy 包是否已安裝,都將重新安裝
設定超時
pip install numpy --timeout=60 # 設定超時連線為 60 秒,預設是 15 秒
3 uninstall
uninstall 用於解除安裝軟體包
pip uninstall numpy
也可使用 requirements 檔案批量解除安裝軟體包
pip install -r requirements.txt
4 freeze
freeze 用於輸出已安裝的軟體包,並以 requirements 檔案的格式顯示,例如
pip freeze altgraph==0.10.2 bdist-mpkg==0.5.0 bonjour-py==0.3 macholib==1.5.1 matplotlib==1.3.1 modulegraph==0.10.4 numpy==1.8.0rc1 pip==18.0 ···
將 requirements 匯出到指定檔案中,注意 “ > ”,檔名稱隨意。
pip freeze > d:\test.txt
pip freeze > d:\requirements.txt
5 list
list 指令用於列舉已安裝的軟體包。它含有很多其他的功能。
pip list #列出所有安裝的庫 pip list --outdated #列出所有過期的庫 pip list -o # --outdated的簡寫,列出所有過期的庫
6 show
show 指令用於顯示包所在目錄及資訊
pip show SomeProject
檢視具體資訊
pip show -f SomeProject
可檢視安裝包的版本,安裝位置,依賴的安裝包以及被被那些安裝包依賴。
7 search
search 指令用於根據使用者提供的關鍵字搜尋包 用法是pip search <搜尋關鍵字>
,例如
numpy (1.16.4) - NumPy is the fundamental package for array computing with Python. INSTALLED: 1.15.4 LATEST: 1.16.4 numpy-utils (0.1.5) - NumPy utilities. numpy-cloud (0.0.5) - Numpy in the cloud numpy-turtle (0.1) - Turtle graphics with NumPy ···
因上求緣,果上努力~~~~ 作者:希望每天漲粉,轉載請註明原文連結:https://www.cnblogs.com/BlairGrowing/p/15410870.html