一.Pip的安裝方法
1.在Windows中的安裝方法
操作環境:
- Windows10
- Python3.7
其實你在安裝python的時候,pip就隨同一起安裝了。一般情況下,可以直接使用,如果不能使用,基本上就是沒有添加環境變量而已。添加下環境變量就可以正常使用了。
<code>C:\\Users\\\\xxx1\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\/<code>
說明:xxx1代表你的用戶名
不過在python的一些老版本中,的確有沒有自帶安裝的,我們就需要自己安裝了,不過安裝也挺簡單的①.在網址https://pip.pypa.io/en/latest/installing 下載get-pip.py文件,放在python的根目錄下②.在dos命令行中進入get-pip.py所在目錄目錄,執行下
<code>python get-pip.py/<code>
③.配置環境變量,在PATH中添加C:\\Users\\\\xxx1\\AppData\\Local\\Programs\\Python\\Python37\\Scripts說明:xxx1代表你的用戶名
2.Linux環境(這裡已Ubuntu為例子)
操作環境:
- Ubuntu18.04
- Python3.7
在安裝python的時候pip就隨同安裝了,如果沒有安裝,在ubuntu環境下安裝非常簡單,一個命令搞定。
<code>sudo apt install python-pip/<code>
二.Pip的使用
1 顯示版本和路徑
<code>pip --version/<code>
2 獲取幫助
<code>pip --help/<code>
3 安裝包
<code>pip install SomePackage # 最新版本
pip install SomePackage==1.0.4 # 指定版本/<code>
4 換國內源安裝包(阿里源)
<code>pip install arrow -i http://mirrors.aliyun.com/pypi/simple//<code>
5 升級包
<code>pip install --upgrade SomePackage # 最新版本
pip install --upgrade SomePackage==1.0.4 # 指定版本/<code>
6 卸載包
<code>pip uninstall SomePackage/<code>
7 列出已安裝的包
<code>pip list/<code>
7 查看已經安裝的包及版本信息
<code>pip freeze/<code>
輸入 pip freeze 後顯示如下
<code>asn1crypto==0.24.0
attrs==17.4.0
Automat==0.6.0
blinker==1.4/<code>
8 搜索包
<code>pip search SomePackage/<code>
輸入 pip search arrow 顯示如下(會顯示包名包含arrow的所有的包)
<code>vaex-arrow (0.4.2) - Arrow support for vaex
Marshmallow-Arrow (1.0) - A Marshmallow Custom Field for Arrow objects.
arrow-fatisar (0.5.3) - ("arrow" fork) Better dates and times forPython
django-arrow-field (0.3.0) - Django arrow datetime field
pandoc-beamer-arrow (0.1.2) - A pandoc filter for adding arrows inBeamer/LaTeX
arrow (0.15.5) - Better dates & times for Python/<code>
9 查看指定包的詳細信息
<code>pip show SomePackage/<code>
輸入 pip show arrow 顯示如下
<code>Name: arrow
Version: 0.15.5
Summary: Better dates & times for Python
Home-page: https://arrow.readthedocs.io
Author: Chris Smith
Author-email: [email protected]
License: Apache 2.0
Location: /home/xionglihong/.local/lib/python3.6/site-packages
Requires: python-dateutil/<code>
閱讀更多 熊利宏Python 的文章