pip常用命令

2019-06-15  本文已影响0人  beeworkshop
  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参数解释

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的时候,加上参数-i和镜像地址(如https://pypi.tuna.tsinghua.edu.cn/simple)。
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。

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

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
[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

安装编译环境

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会创建共享库(shared library),否则只会创建静态库(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

然后执行如下命令
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
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
上一篇 下一篇

猜你喜欢

热点阅读