pip常用命令

  1. pip升級
    pip show pip
    python -m pip install --upgrade pip

  2. pip安裝包
    pip install 安裝包名

  3. pip查看是否已安裝
    pip show [--files] 安裝包名

  4. pip檢查哪些包需要更新
    pip list --outdated

  5. pip升級包
    pip install --upgrade 要升級的包名

  6. pip卸載包
    pip uninstall 要卸載的包名

  7. pip參數(shù)解釋

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 local and 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 help for 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 to 3 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).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
                              (a)bort.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the
                              certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output
  1. 常用命令
pip install ./downloads/SomePackage-1.0.4.tar.gz 
pip install http://my.package.repo/SomePackage-1.0.4.zip
pip search "query"   ##查詢package的具體名稱
pip uninstall package-name  ##卸載
pip install SomePackage==1.0.4  ##指定版本的安裝
pip install --upgrade SomePackage  ##package 版本升級
  1. 將pip源更換到國內鏡像
常用的國內鏡像包括:
(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
(5)華中科技大學http://pypi.hustunique.com/

注意:新版ubuntu要求使用https源。
設置方法如下(以清華鏡像為例,其它鏡像同理):
(1)臨時使用:
可以在使用pip的時候,加上參數(shù)-i和鏡像地址(如https://pypi.tuna.tsinghua.edu.cn/simple)。
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,這樣就會從清華鏡像安裝pandas庫。

(2)永久修改,一勞永逸:

  • Linux下,修改 ~/.pip/pip.conf (沒有就創(chuàng)建一個文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)
    內容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
  • windows下,直接在user目錄中創(chuàng)建一個pip目錄,如:C:\Users\xx\pip,然后新建文件pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini文件中輸入以下內容(以豆瓣鏡像為例):
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com

然后再安裝
pip install pandas

  1. conda修改為國內源

運行以下命令:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

或者直接修改.condarc文件

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

.condarc文件路徑

windows     c:\users\xxx
linux       ~/.condarc

可用源

清華
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
中科大
http://mirrors.ustc.edu.cn/anaconda/pkgs/free/
  1. Centos7安裝python3.x

安裝編譯環(huán)境

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

下載python3 tarball

wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

解壓

tar -xvJf Python-3.7.3.tar.xz

安裝到指定路徑

cd Python-3.7.3
./configure --prefix=/usr/local/bin/python3 --enable-shared --enable-universalsdk
make
make install
這里
--enable-shared 保證python會創(chuàng)建共享庫(shared library),否則只會創(chuàng)建靜態(tài)庫(static library)
--enable-universalsdk 保證python會被編譯成64位

解決如下報錯

報錯:
python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

如下處理:
find /usr/local -name libpython3.7m.so.1.0
回顯
/usr/local/bin/python3/lib/libpython3.7m.so.1.0
看一下目錄
cd /etc/ld.so.conf.d/
ll
total 20
-rw-r--r--. 1 root root 19 Oct 31  2018 dyninst-x86_64.conf
-r--r--r--. 1 root root 63 Aug 23  2017 kernel-3.10.0-693.el7.x86_64.conf
-rw-r--r--. 1 root root 17 Aug  5  2017 mariadb-x86_64.conf

然后執(zhí)行如下命令
echo '/usr/local/bin/python3/lib' > /etc/ld.so.conf.d/python3.conf
ldconfig

制作鏈接

ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3

驗證

python3 -V
pip3 show pip

把默認python2.7設置成python3

mv /usr/bin/python /usr/bin/old_python
ln -s /usr/local/bin/python3/bin/python3.7 /usr/bin/python

vim /usr/bin/yum
把第一行的路徑改成剛才的/usr/bin/old_python:
#!/usr/bin/old_python
這樣yum就不會報錯了
  1. install pip for python3.x
wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6.tar.gz
python3 setup.py build
python3 setup.py install
  • 安裝pip
wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3 setup.py build
python3 setup.py install
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容