目录

前言 1.1

Python包管理器概述 1.2

pip 1.3

常用命令 1.3.1

pip install 1.3.1.1

用pip安装库 1.3.1.1.1

给pip下载加速 1.3.1.1.2

更换pip的源 1.3.1.1.2.1

给pip加代理 1.3.1.1.2.2

pip uninstall 1.3.1.2

pip show 1.3.1.3

pip list 1.3.1.4

pip search 1.3.1.5

pip freeze 1.3.1.6

常见问题 1.3.2

command not found pip 1.3.2.1

Errno 13 Permission denied 1.3.2.2

Retrying after connection broken 1.3.2.3

确认pip是Pyhton2还是Python3 1.3.2.4

不用pip安装python库 1.3.2.5

相关 1.3.3

pipenv 1.3.3.1

通过pip查看site-packages位置 1.3.3.2

附录 1.4

参考资料 1.4.1

前言

管理好Python的库：包管理器

最新版本：v1.0

更新时间：20210425

简介

介绍如何用包管理器尤其是pip去管理好Python的库。先进行基本的概述，包括常见的Python包管理器有easy_install、setuptools、pip；然后详细阐述pip：包括常用的命令，比如pip install、pip uninstall、pip show、pip list、pip search、pip freeze。其中包括pip install的各种语法和各种举例说明；以及如何给pip下载加速，包括更换源和加代理的方法和具体操作步骤；总结了pip常见的一些问题，包括command not found pip、Could not install packages due to an EnvironmentError Errno 13 Permission denied、Retrying after connection broken by NewConnectionError、使用pip时要注意是python2还是python3、以及部分可以情况下不用pip管理python的库；然后整理了pip相关的一些内容，包括虚拟环境工具pipenv、通过pip查看site-packages位置等；最后给出参考资料。

源码+浏览+下载

本书的各种源码、在线浏览地址、多种格式文件下载如下：

Gitbook源码

crifan/python_summary_package_manager: 管理好Python的库：包管理器

如何使用此Gitbook源码去生成发布为电子书

详见：crifan/gitbook_template: demo how to use crifan gitbook template and demo

在线浏览

管理好Python的库：包管理器 book.crifan.com

管理好Python的库：包管理器 crifan.github.io

离线下载阅读

管理好Python的库：包管理器 PDF

管理好Python的库：包管理器 ePub

管理好Python的库：包管理器 Mobi

版权说明

此电子书教程的全部内容，如无特别说明，均为本人原创和整理。其中部分内容参考自网络，均已备注了出处。如有发现侵犯您版权，请通过邮箱联系我 admin 艾特 crifan.com，我会尽快删除。谢谢合作。

鸣谢

感谢我的老婆陈雪的包容理解和悉心照料，才使得我crifan有更多精力去专注技术专研和整理归纳出这些电子书和技术教程，特此鸣谢。

更多其他电子书

本人crifan还写了其他100+本电子书教程，感兴趣可移步至：

crifan/crifan_ebook_readme: Crifan的电子书的使用说明

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:28:49

Python包管理器概述

Python包管理器概述

Python开发期间，经常涉及到需要安装各种Python库，用于实现不同的功能。

Python中用包管理器来管理Python库。

目前现存有很多种Python的包管理器：

Python包管理器

easy_install

easy_install基于旧的包格式：egg

现在很少用了

只有当你只有egg的格式时，才需要用到easy_install

setuptools

setuptools包含了（内部用到了）easy_install

现在用的很少

pip

历史

2008年发布

内部实现

基于新的包的格式：wheel

pip往往是Python自带就有的，无需额外安装。且功能强大，很好用。

pip是目前Python中最常见的包管理器

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:05:36

pip

pip

pip是Python中最常用的包管理器。

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:14:55

常用命令

pip常用命令

pip常用的命令有：

pip install

pip uninstall

pip search

pip show

pip list

pip freeze

后续会详细介绍。

典型的pip使用逻辑

对于使用pip管理Python库的典型逻辑是：

用virtualevn或pipenv等创建某Python项目的Python虚拟环境后

进入虚拟环境，然后

去用pip install xxx安装需要用到的库

Python项目开发期间：

如果不需要某库，用pip uninstall xxx去删除掉

如果不知道某个库的包名是什么，但知道库的名字，可以用pip search xxx去找找源中是否有该库，以及具体包名是啥

想要知道具体某个已安装的库的详情（比如版本，具体安装位置等），可以用pip show xxx去查看

查看当前都安装了哪些库，用pip list

项目开发完毕后，冻结环境，即保存好当前Python环境，用：

pip freeze > requirements.txt

即生成了requirements.txt，记录了当前安装了哪些Python库，及其版本信息。

如果别人（比如你的同事接手你的项目）想要重新恢复你的Python项目的环境，则去：

（用和你一样的virtualenv或pipenv）创建对应的虚拟环境后，进入虚拟环境，再去：

pip install -r requirements.txt

安装全部的库，即恢复出了相同的Python环境。

即可，接着愉快的继续（协作）开发项目了。

pip语法

pip的语法，可以通过help查看到：

pip --help

贴出来供参考：

 ⚙ limao@xxx  ~  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.
  cache                       Inspect and manage pip's wheel cache.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  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.
  --no-input                  Disable prompting for input.
  --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 or host:port pair 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.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be removed in the future.

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:28:00

pip install

pip install

可以用pip install安装Python的库。

语法介绍

可通过

pip install --help

或：

pip help install

查看细节。

贴出来供参考：

⚙ limao@xxx  ~  pip install --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.
  --pre                       Include pre-release and development versions. By default, pip only finds stable versions.
  -e, --editable <path/url>   Install a project in editable mode (i.e. setuptools "develop mode") from a local project path
                              or a VCS url.
  -t, --target <dir>          Install packages into <dir>. By default this will not replace existing files/folders in <dir>.
                              Use --upgrade to replace existing packages in <dir> with new versions.
  --platform <platform>       Only use wheels compatible with <platform>. Defaults to the platform of the running system. Use
                              this option multiple times to specify multiple platforms supported by the target interpreter.
  --python-version <python_version>
                              The Python interpreter version to use for wheel and "Requires-Python" compatibility checks.
                              Defaults to a version derived from the running interpreter. The version can be specified using
                              up to three dot-separated integers (e.g. "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3"). A major-
                              minor version can also be given as a string without dots (e.g. "37" for 3.7.0).
  --implementation <implementation>
                              Only use wheels compatible with Python implementation <implementation>, e.g. 'pp', 'jy', 'cp',
                              or 'ip'. If not specified, then the current interpreter implementation is used.  Use 'py' to
                              force implementation-agnostic wheels.
  --abi <abi>                 Only use wheels compatible with Python abi <abi>, e.g. 'pypy_41'. If not specified, then the
                              current interpreter abi tag is used. Use this option multiple times to specify multiple abis
                              supported by the target interpreter. Generally you will need to specify --implementation,
                              --platform, and --python-version when using this option.
  --user                      Install to the Python user install directory for your platform. Typically ~/.local/, or
                              %APPDATA%\Python on Windows. (See the Python documentation for site.USER_BASE for full
                              details.)
  --root <dir>                Install everything relative to this alternate root directory.
  --prefix <dir>              Installation prefix where lib, bin and other top-level folders are placed
  --src <dir>                 Directory to check out editable projects into. The default in a virtualenv is "<venv
                              path>/src". The default for global installs is "<current dir>/src".
  -U, --upgrade               Upgrade all specified packages to the newest available version. The handling of dependencies
                              depends on the upgrade-strategy used.
  --upgrade-strategy <upgrade_strategy>
                              Determines how dependency upgrading should be handled [default: only-if-needed]. "eager" -
                              dependencies are upgraded regardless of whether the currently installed version satisfies the
                              requirements of the upgraded package(s). "only-if-needed" -  are upgraded only when they do not
                              satisfy the requirements of the upgraded package(s).
  --force-reinstall           Reinstall all packages even if they are already up-to-date.
  -I, --ignore-installed      Ignore the installed packages, overwriting them. This can break your system if the existing
                              package is of a different version or was installed with a different package manager!
  --ignore-requires-python    Ignore the Requires-Python information.
  --no-build-isolation        Disable isolation when building a modern source distribution. Build dependencies specified by
                              PEP 518 must be already installed if this option is used.
  --use-pep517                Use PEP 517 for building source distributions (use --no-use-pep517 to force legacy behaviour).
  --install-option <options>  Extra arguments to be supplied to the setup.py install command (use like --install-option="--
                              install-scripts=/usr/local/bin"). Use multiple --install-option options to pass multiple
                              options to setup.py install. If you are using an option with a directory path, be sure to use
                              absolute path.
  --global-option <options>   Extra global options to be supplied to the setup.py call before the install command.
  --compile                   Compile Python source files to bytecode
  --no-compile                Do not compile Python source files to bytecode
  --no-warn-script-location   Do not warn when installing scripts outside PATH
  --no-warn-conflicts         Do not warn about broken dependencies
  --no-binary <format_control>
                              Do not use binary packages. Can be supplied multiple times, and each time adds to the existing
                              value. Accepts either ":all:" to disable all binary packages, ":none:" to empty the set (notice
                              the colons), or one or more package names with commas between them (no colons). Note that some
                              packages are tricky to compile and may fail to install when this option is used on them.
  --only-binary <format_control>
                              Do not use source packages. Can be supplied multiple times, and each time adds to the existing
                              value. Accepts either ":all:" to disable all source packages, ":none:" to empty the set, or one
                              or more package names with commas between them. Packages without binary distributions will fail
                              to install when this option is used on them.
  --prefer-binary             Prefer older binary packages over newer source packages.
  --require-hashes            Require a hash to check each requirement against, for repeatable installs. This option is
                              implied when any package in a requirements file has a --hash option.
  --progress-bar <progress_bar>
                              Specify type of progress to be displayed [off|on|ascii|pretty|emoji] (default: on)
  --no-clean                  Don't clean up build directories.

Package Index Options:
  -i, --index-url <url>       Base URL of the Python Package Index (default https://pypi.org/simple). This should point to a
                              repository compliant with PEP 503 (the simple repository API) or a local directory laid out in
                              the same format.
  --extra-index-url <url>     Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules
                              as --index-url.
  --no-index                  Ignore package index (only looking at --find-links URLs instead).
  -f, --find-links <url>      If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or
                              wheel (.whl) files. If a local path or file:// URL that's a directory,  then look for archives
                              in the directory listing. Links to VCS project URLs are not supported.

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.
  --no-input                  Disable prompting for input.
  --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 or host:port pair 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.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be removed in the future.

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:07:19

用pip安装库

用pip安装库

安装

普通安装

pip install xxx

把pip作为python的模块去安装

/your/specific/python -m pip install xxx

安装特定版本

pip install 'xxx==version_number'

安装A时，同时安装A所依赖的库：B

pip install A[B]

升级

升级已安装的库

pip install --upgrade xxx

等价于

pip install -U xxx

安装来源和方式

从文件安装

whl文件

在线文件

pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.7.0rc1-py3-none-any.whl

本地文件

pip install /Users/crifan/dev/dev_tool/tensorflow/tensorflow-1.7.0rc1-py3-none-any.whl

从源安装

源码包

语法

pip install PackageName --no-index --find-links file:///path/to/your/package

举例

pip install -U SQLAlchemy --no-index --find-links ./SQLAlchemy-1.1.3.tar.gz

pip install举例

pipenv

安装pinenv

pip3 install pipenv --user

用pip升级pipenv

pip install --user --upgrade pipenv

安装Django的sendfile插件

pip3 install django-sendfile

安装Django的CORS插件

pip3 install django-cors-headers

安装查看文件类型的MIME

pip install mime

安装Amazon的boto3

pip install boto3

安装Web自动化工具selenium

pip install -U selenium

安装虚拟环境工具virtualenv

pip install virtualenv

升级virtualenv

pip install --upgrade virtualenv

安装MongoDB数据库的Python的driver

pip install pymongo

升级MongoDB

pip install --upgrade pymongo

安装数据库ORM：sqlalchemy

pip install -U sqlalchemy

安装指定版本

pip install 'sqlalchemy==1.1.0b3'

安装爬虫工具scrapy

pip install scrapy

通过python的模块方式调用pip去安装

通过python的模块方式调用pip去安装pylint

/usr/local/bin/python3 -m pip install -U pylint --user

类似的写法

python -m pip install -U pylint

安装之前加额外参数

在重新安装pycurl之前，加上额外的参数

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/opt/openssl/include;pip install pycurl --compile --no-cache-dir

安装库A同时安装依赖库B

安装gunicorn同时安装所依赖的其他库

eventlet

pip install gunicorn[eventlet]

gevent

pip install gunicorn[gevent]

tornado

pip install gunicorn[tornado]

gthread

pip install gunicorn[gthread]

给出部分库的详细安装日志

安装Python项目部署工具supervisor

pip install supervisor

如果遇到权限问题，则加上--user

pip install supervisor --user

详细日志

➜  robotDemo pip install supervisor --user
Collecting supervisor
Collecting meld3&gt;=0.6.5 (from supervisor)
  Using cached https://files.pythonhosted.org/packages/b6/ae/e6d731e4b9661642c1b20591d8054855bb5b8281cbfa18f561c2edd783f7/meld3-1.0.2-py2.py3-none-any.whl
pipenv 11.10.0 requires certifi, which is not installed.
pipenv 11.10.0 requires requests[security], which is not installed.
pipenv 11.10.0 requires virtualenv, which is not installed.
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: meld3, supervisor
  The scripts echo_supervisord_conf, pidproxy, supervisorctl and supervisord are installed in '/Users/crifan/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed meld3-1.0.2 supervisor-3.3.4

安装Excel处理工具openpyxl

pip install openpyxl

详细日志

➜  英语资源 pip install openpyxl
Collecting openpyxl
  Downloading openpyxl-2.5.1.tar.gz (169kB)
    100% |████████████████████████████████| 174kB 1.1MB/s
Collecting jdcal (from openpyxl)
  Downloading jdcal-1.3.tar.gz
Collecting et_xmlfile (from openpyxl)
  Downloading et_xmlfile-1.0.1.tar.gz
Building wheels for collected packages: openpyxl, jdcal, et-xmlfile
  Running setup.py bdist_wheel for openpyxl … done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/98/5e/20/70cde417026f1e168acdac7babf47b204a7b752b1a8e6bb795
  Running setup.py bdist_wheel for jdcal … done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/0f/63/92/19ac65ed64189de4d662f269d39dd08a887258842ad2f29549
  Running setup.py bdist_wheel for et-xmlfile … done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/99/f6/53/5e18f3ff4ce36c990fa90ebdf2b80cd9b44dc461f750a1a77c
Successfully built openpyxl jdcal et-xmlfile
Installing collected packages: jdcal, et-xmlfile, openpyxl
Successfully installed et-xmlfile-1.0.1 jdcal-1.3 openpyxl-2.5.1

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:06:41

给pip下载加速

给pip下载加速

用pip去安装库时，往往速度很慢，甚至连不上

因为通过pip去安装库，需要先去下载库的安装包，而安装包的来源，默认的是：

https://pypi.org

其服务器在国外，国内连接的速度往往很慢，导致：

pip安装库的速度很慢

解决办法：

方式1：更换pip的源

为某个国内的pypi.org的镜像服务器

国内用户访问速度更快

方式2：给网络加代理

通过代理访问 pypi.org，实现下载加速的效果

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:06:30

更换pip的源

更换pip的源

思路

新建（全局的、系统的）pip的配置文件

Windows：%HOMEPATH%\pip\pip.ini

举例

C:\Users\Administrator\pip\pip.ini

macOS：~/.pip/pip.conf

举例

/Users/crifanli/.pip/pip.conf

给配置文件加上国内的某个pip的源

步骤

（如果不存在的话）新建pip的配置文件

mkdir ~/.pip
vim ~/.pip/pip.conf

去更新配置内容，格式是：

[global]
index-url = pypi_mirror_url

[install]
trusted-host=pypi_mirror_url_host

参数解释：

pypi_mirror_url

常见可选的pip的源

阿里云：http://mirrors.aliyun.com/pypi/simple/

清华大学：https://pypi.tuna.tsinghua.edu.cn/simple

豆瓣：http://pypi.douban.com/simple

pypi_mirror_url_host

对应host

mirrors.aliyun.com

pypi.tuna.tsinghua.edu.cn

pypi.douban.com

下面给出实例：

推荐：清华大学的pip的源

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

实测：速度暴快，>1MB/s

推荐：阿里云的pip的源

[global]
index-url = http://mirrors.aliyun.com/pypi/simple

[install]
trusted-host=mirrors.aliyun.com

速度也不错，也很稳定。

可选：豆瓣的pip的源

[global]
index-url = http://pypi.douban.com/simple

[install]
trusted-host=pypi.douban.com

待确认：淘宝taobao的源

后来看到淘宝的npm的镜像

taobao Mirrors

其中也能找到python的源：

Python Mirror

抽空试试是否可用

特殊：现已不推荐：ustc的源

之前推荐的

[global]
index-url = http://pypi.mirrors.ustc.edu.cn/simple

[install]
trusted-host=pypi.mirrors.ustc.edu.cn

现已不推荐

原因：

其内部已跳转到tsinghua的源

202104 后记：现已跳转到 BFSU（北京外国语大学）的镜像了：mirrors.bfsu.edu.cn

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:06:21

给pip加代理

给pip加代理

此处也可以通过给pip加代理的方式实现加速pip下载。

实现方式：用pip安装时，加上代理：

pip --proxy http://127.0.0.1:1087 install pandas

其中：

代理地址：127.0.0.1:1087

对应着此处本地的ss的http代理：

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:06:10

pip uninstall

pip uninstall

卸载已安装的Python库

  pip uninstall xxx

有时候，pip会提示你，确认是否删除，需要输入y才能继续删除

如果不希望被提示，直接删除，可以加上y

pip uninstall -y xxx

想要卸载某个特定版本，可以指定版本号

  pip uninstall xxx==verion_number

pip uninstall举例

卸载（已安装，但有问题的）pycurl

  pip uninstall pycurl

不询问(是否删除)而直接删除

pip uninstall -y pycurl

卸载uiautomator2

  pip uninstall uiautomator2

卸载facebook-wda

  pip uninstall facebook-wda

卸载1.7.0rc1版本的tensorflow

  pip uninstall tensorflow==1.7.0rc1

卸载pyinstaller

  pip uninstall pyinstaller

卸载pipenv

  pip3 uninstall pipenv

卸载pip自己

  python -m pip uninstall pip

卸载mime

  pip uninstall mime

卸载selenium

  pip uninstall selenium

给出部分库的详细卸载日志

卸载virtualenv

  pip uninstall virtualenv

完整log举例

  ➜  virtualenv pip uninstall virtualenv
  Uninstalling virtualenv-15.1.0:
  /usr/local/bin/virtualenv
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/DESCRIPTION.rst
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/INSTALLER
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/METADATA
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/RECORD
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/WHEEL
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/entry_points.txt
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/metadata.json
  /usr/local/lib/python2.7/site-packages/virtualenv-15.1.0.dist-info/top_level.txt
  /usr/local/lib/python2.7/site-packages/virtualenv.py
  /usr/local/lib/python2.7/site-packages/virtualenv.pyc
  /usr/local/lib/python2.7/site-packages/virtualenv_support/__init__.py
  /usr/local/lib/python2.7/site-packages/virtualenv_support/__init__.pyc
  /usr/local/lib/python2.7/site-packages/virtualenv_support/argparse-1.4.0-py2.py3-none-any.whl
  /usr/local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl
  /usr/local/lib/python2.7/site-packages/virtualenv_support/setuptools-28.8.0-py2.py3-none-any.whl
  /usr/local/lib/python2.7/site-packages/virtualenv_support/wheel-0.29.0-py2.py3-none-any.whl
  Proceed (y/n)? y
  Successfully uninstalled virtualenv-15.1.0

期间需要输入y才可继续卸载

想要实现，不需要输入y就可以直接自动卸载，可以加上-y参数

pip uninstall -y virtualenv

卸载supervisor

  pip2 uninstall supervisor

详细日志

  [root@xxx-general-01 robotDemo]# pip2 uninstall supervisor
  Uninstalling supervisor-3.3.4:
  Would remove:
      /usr/bin/echo_supervisord_conf
      /usr/bin/pidproxy
      /usr/bin/supervisorctl
      /usr/bin/supervisord
      /usr/lib/python2.7/site-packages/supervisor-3.3.4-py2.7-nspkg.pth
      /usr/lib/python2.7/site-packages/supervisor-3.3.4-py2.7.egg-info
      /usr/lib/python2.7/site-packages/supervisor/childutils.py
      /usr/lib/python2.7/site-packages/supervisor/confecho.py
      /usr/lib/python2.7/site-packages/supervisor/datatypes.py
      /usr/lib/python2.7/site-packages/supervisor/dispatchers.py
      /usr/lib/python2.7/site-packages/supervisor/events.py
      /usr/lib/python2.7/site-packages/supervisor/http.py
      /usr/lib/python2.7/site-packages/supervisor/http_client.py
      /usr/lib/python2.7/site-packages/supervisor/loggers.py
      /usr/lib/python2.7/site-packages/supervisor/medusa/*
      /usr/lib/python2.7/site-packages/supervisor/options.py
      /usr/lib/python2.7/site-packages/supervisor/pidproxy.py
      /usr/lib/python2.7/site-packages/supervisor/poller.py
      /usr/lib/python2.7/site-packages/supervisor/process.py
      /usr/lib/python2.7/site-packages/supervisor/rpcinterface.py
      /usr/lib/python2.7/site-packages/supervisor/scripts/loop_eventgen.py
      /usr/lib/python2.7/site-packages/supervisor/scripts/loop_listener.py
      /usr/lib/python2.7/site-packages/supervisor/scripts/sample_commevent.py
      /usr/lib/python2.7/site-packages/supervisor/scripts/sample_eventlistener.py
      /usr/lib/python2.7/site-packages/supervisor/scripts/sample_exiting_eventlistener.py
      /usr/lib/python2.7/site-packages/supervisor/skel/sample.conf
      /usr/lib/python2.7/site-packages/supervisor/socket_manager.py
      /usr/lib/python2.7/site-packages/supervisor/states.py
      /usr/lib/python2.7/site-packages/supervisor/supervisorctl.py
      /usr/lib/python2.7/site-packages/supervisor/supervisord.py
      /usr/lib/python2.7/site-packages/supervisor/tests/*
      /usr/lib/python2.7/site-packages/supervisor/ui/images/button_refresh.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/button_restart.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/button_stop.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/icon.png
      /usr/lib/python2.7/site-packages/supervisor/ui/images/rule.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/state0.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/state1.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/state2.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/state3.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/images/supervisor.gif
      /usr/lib/python2.7/site-packages/supervisor/ui/status.html
      /usr/lib/python2.7/site-packages/supervisor/ui/stylesheets/supervisor.css
      /usr/lib/python2.7/site-packages/supervisor/ui/tail.html
      /usr/lib/python2.7/site-packages/supervisor/version.txt
      /usr/lib/python2.7/site-packages/supervisor/web.py
      /usr/lib/python2.7/site-packages/supervisor/xmlrpc.py
  Proceed (y/n)? y
  Successfully uninstalled supervisor-3.3.4

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:11:33

pip show

pip show

可以用

pip show

去查看已安装的库/包的详细信息。

语法：

pip show xxx

pip show举例

Django

[root@xx-general-01 xxx]# pip3 show Django
Name: Django
Version: 2.0.6
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD
Location: /usr/lib/python3.4/site-packages
Requires: pytz
Required-by: django-redis

supervisor

[root@xx-general-01 robotDemo]# pip show supervisor
Name: supervisor
Version: 3.3.4
Summary: A system for controlling process state under UNIX
Home-page: http://supervisord.org/
Author: Chris McDonough
Author-email: chrism@plope.com
License: BSD-derived (http://www.repoze.org/LICENSE.txt)
Location: /usr/lib/python2.7/site-packages
Requires: meld3
Required-by:

kafka

# pip3 show kafka
Name: kafka
Version: 1.3.5
Summary: Pure Python client for Apache Kafka
Home-page: https://github.com/dpkp/kafka-python
Author: Dana Powers
Author-email: dana.powers@gmail.com
License: Apache License 2.0
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by:

flask

(xxx) ➜  xxx pip show flask
Metadata-Version: 2.0
Name: Flask
Version: 0.11.1
Summary: A microframework based on Werkzeug, Jinja2 and good intentions
Home-page: http://github.com/pallets/flask/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
Installer: pip
License: BSD
Location: /root/Envs/xxx/lib/python2.7/site-packages
Requires: itsdangerous, Jinja2, Werkzeug, click
Classifiers:
  Development Status :: 4 – Beta
  Environment :: Web Environment
  Intended Audience :: Developers
  License :: OSI Approved :: BSD License
  Operating System :: OS Independent
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.6
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4
  Programming Language :: Python :: 3.5
  Topic :: Internet :: WWW/HTTP :: Dynamic Content
  Topic :: Software Development :: Libraries :: Python Modules
Entry-points:
  [console_scripts]
  flask=flask.cli:main

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:11:20

pip list

pip list

可以用

pip list

来查看当前（Python）环境中的已安装的Python库（及其版本信息）

pip list举例

 ⚙ limao@xxx  ~  pip list
Package           Version    Location
----------------- ---------- ---------------------------------------------------------
adbutils          0.7.1
apkutils2         1.0.0
asn1crypto        1.3.0
attrdict          2.0.1
attrs             19.3.0
Automat           20.2.0
autopep8          1.4.4
beautifulsoup4    4.8.2
blinker           1.4
Brotli            1.0.7
bs4               0.0.1
cached-property   1.5.1
certifi           2019.11.28
cffi              1.14.0
chardet           3.0.4
cigam             0.0.3
Click             7.0
constantly        15.1.0
cryptography      2.4.2
cssselect         1.1.0
decorator         4.4.1
defusedxml        0.6.0
Deprecated        1.2.7
deprecation       2.0.7
facebook-wda      1.3.4
Flask             1.1.1
Flask-Login       0.5.0
future            0.18.2
greenlet          1.0.0
h11               0.9.0
h2                3.1.1
hpack             3.0.0
humanize          0.5.1
hyperframe        5.2.0
hyperlink         19.0.0
idna              2.8
incremental       17.5.0
itemadapter       0.1.0
itsdangerous      1.1.0
Jinja2            2.11.1
json5             0.9.5
kaitaistruct      0.8
ldap3             2.6.1
logzero           1.5.0
lxml              4.5.0
MarkupSafe        1.1.1
mitmproxy         5.0.1
numpy             1.18.1
packaging         20.1
pandas            0.24.2
parsel            1.6.0
passlib           1.7.2
PGet              0.5.0
Pillow            7.0.0
pip               21.0.1
pipenv            2018.11.26
playwright        1.10.0
progress          1.5
Protego           0.1.16
protobuf          3.10.0
publicsuffix2     2.20191221
py                1.8.1
pyasn1            0.4.8
pyasn1-modules    0.2.8
pycodestyle       2.5.0
pycparser         2.19
pycurl            7.43.0.5
PyDispatcher      2.0.5
pyee              8.1.0
pyelftools        0.26
PyHamcrest        2.0.2
pyOpenSSL         19.0.0
pyparsing         2.4.6
pyperclip         1.7.0
pyquery           1.4.1
pyspider          0.3.10
python-dateutil   2.8.1
pytz              2019.3
PyYAML            5.3
queuelib          1.5.0
requests          2.22.0
retry             0.9.2
ruamel.yaml       0.16.7
Scrapy            2.2.1
service-identity  18.1.0
setuptools        41.2.0
six               1.14.0
sortedcontainers  2.1.0
soupsieve         1.9.5
spark-parser      1.8.9
tblib             1.7.0
tornado           4.5.3
tushare           1.2.48
Twisted           20.3.0
typing-extensions 3.7.4.3
u-msgpack-python  2.6.0
uiautomator2      2.5.3
uncompyle6        3.6.2      /Users/limao/dev/tools/python_decompile/python-uncompyle6
urllib3           1.25.8
urwid             2.0.1
virtualenv        16.7.9
virtualenv-clone  0.5.3
w3lib             1.22.0
weditor           0.4.2
Werkzeug          1.0.0
wheel             0.35.1
whichcraft        0.6.1
wrapt             1.11.2
WsgiDAV           3.0.3
wsproto           0.14.1
xdis              4.2.2
xmltodict         0.12.0
zope.interface    5.1.0
zstandard         0.12.0

另外一个pipenv的虚拟环境中的例子：

➜  tensorflow pip list --format=columns
Package                       Version
----------------------------- ---------
asn1crypto                    0.24.0
astroid                       1.5.3
attrs                         17.3.0
Automat                       0.6.0
backports.functools-lru-cache 1.4
browsermob-proxy              0.8.0
certifi                       2017.11.5
cffi                          1.11.2
chardet                       3.0.4
configparser                  3.5.0
constantly                    15.1.0
cryptography                  2.1.4
cssselect                     1.0.1
enum34                        1.1.6
hyperlink                     17.3.1
idna                          2.6
incremental                   17.5.0
ipaddress                     1.0.19
isort                         4.2.15
lazy-object-proxy             1.3.1
lxml                          4.1.1
mccabe                        0.6.1
parsel                        1.2.0
pip                           9.0.1
pyasn1                        0.4.2
pyasn1-modules                0.2.1
pycparser                     2.18
PyDispatcher                  2.0.5
pylint                        1.7.2
pyOpenSSL                     17.5.0
queuelib                      1.4.2
requests                      2.18.4
Scrapy                        1.4.0
selenium                      3.7.0
service-identity              17.0.0
setuptools                    38.4.0
singledispatch                3.4.0.3
six                           1.10.0
speedtest-cli                 1.0.7
Twisted                       17.9.0
urllib3                       1.22
virtualenv                    15.1.0
w3lib                         1.18.0
wheel                         0.30.0
wrapt                         1.10.11
zope.interface                4.4.3

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:09:37

pip search

pip search

当想要安装某个库，但却又不知道该库的包名时，可以用：

pip search xxx

去数据源中查询有哪些相关的包。

pip search举例

kafka

[root@xxx-dev-01 exercise]# pip3 search kafka
kafka (1.3.5)                                     - Pure Python client for Apache Kafka
  INSTALLED: 1.3.5 (latest)
heroku-kafka (2.1.2)                              - Python kafka package for use with heroku's kafka.
pytest-kafka (0.3.1)                              - Zookeeper, Kafka server, and Kafka consumer fixtures for Pytest
kafka-utils (2.3.0)                               - Kafka management utils
chance-kafka (0.0.6)                              - The kafka library for chancefocus
dask-kafka (0.1.0.dev0)                           - Dask-Kafka reader
kafka-bundle (1.0)                                - Kafka support for applauncher
kafka-helper (0.2)                                - Makes it easy to use the kafka-python library with Apache Kafka on Heroku
scrapy-kafka (0.1.1)                              - Kafka-based components for Scrapy
kafka-connector (0.0.7)                           - A python module for communication with Kafka.
kafka-logger (0.3.0)                              - A simple Kafka logger in Python.
eventcore-kafka (0.3.3)                           - Produce and consume events with Kafka.
kafka-shell (0.1.1)                               - A supercharged, interactive Kafka shell built on top of the existing Kafka CLI tools.
kafka-quixey (0.9.0-q3)                           - Pure Python client for Apache Kafka
confluent-kafka (1.1.0)                           - Confluent's Python client for Apache Kafka
kafka-python (1.4.6)                              - Pure Python client for Apache Kafka
timi-kafka (0.0.2)                                - Pure Python client for Apache Kafka
kafka-scanner (0.3.4)                             - High Level Kafka Scanner, supporting inverse consuming and deduplication. Based on kafka-python library.
log-to-kafka (1.1.4)                              - log to kafka
sentry-kafka (1.1)                                - A Sentry extension which integrates with Apache Kafka.
kafka-rest (0.0.12)                               - Async client for Confluent's Kafka REST Proxy
kafka-tools (0.1.9)                               - A collection of tools and scripts for working with Apache Kafka
kafka-connect-python (0.0.3)                      - Kafka Connect Module
kafka-dev-tools (0.0.1)                           - Tools for Kafka developers
kafka-python-with-confluent-kafka (0.2)           - This python project use to consume/produce/manager the Kafka
aio-kafka-daemon (0.5.1)                          - Asynchronous Kafka Processing Daemon
scrapy-kafka-export (0.1.1)                       - Export Scrapy items to Kafka
kafka-rest-client (0.8.0)                         - A python kafka rest client
chatora.confluent-kafka-ext (0.3)                 - Apache Kafka and Schema Registry client libraries for Python on top of confluent-kafka-python.
kafka-utils-netease (1.4.9)                       - Easy way to use Kafka in python
stack-kafka-python (1.4.11)                       - Pure Python client for Apache Kafka
scrapy-kafka-redis (0.0.7)                        - Kafka and Redis based components for Scrapy.
kafka-splunk-connector (1.0.6)                    - Library that connects the kafka topic to splunk
confluent-kafka-helpers (0.7.3)                   - Helpers for Confluent's Kafka Python client
netbox-kafka-producer (1.0.10)                    - Easily publish NetBox changes to Kafka
gc-kafka-python (0.9.8)                           - Pure Python client for Apache Kafka
robinhood-kafka-python (1.4.3)                    - Pure Python client for Apache Kafka
kafka-connect-healthcheck (0.1.0)                 - A simple healthcheck wrapper to monitor Kafka Connect.
kafka-logging-handler (0.2.2)                     - A Python logging handler library for Kafka consumers.
netbox-kafka-consumer (1.0.6)                     - Easily consume NetBox changes from Kafka
heroku-kafka-eze (0.0.2)                          - Python kafka package for use with heroku's kafka. You'll only need your heroku api key and app name
logwatcher-kafka-plugin (1.0)                     - LogWatcher Plugin for Sending log lines to a Kafka Topic
python-elk-kafka (0.0.1)                          - A python3 elk project use kafka to send messages
confluent-kafka-smyte (0.9.3)                     - Smyte fork of Confluent's Apache Kafka client for Python
swissbib-kafka-event-hub (2.2.0)                  - Swissbib Kafka Event Hub
kafka-log-handler (1.2)                           - Simple python logging handler for forwarding logs to a kafka server.
python-kafka-logger (0.5)                         - Simple python logging handler for forwarding logs to a kafka server.
batching-kafka-consumer (0.0.4)                   - Kafka Consumer abstraction that assists with processing batches and committing offsets.
python-kafka-logging (0.6)                        - Simple python logging handler for forwarding logs to a kafka server.
reverse-kafka-logger (0.1.2)                      - grep kafka message reversely from the end offset to start offset
pipelinewise-tap-kafka (1.0.0)                    - Singer.io tap for extracting data from Kafka topic - PipelineWise compatible
ctodd-python-lib-kafka (1.0.2)                    - Python utilities used for interacting with Apache Kafka
kafka-avro-binary-consumer (0.0.0.2)              - Kafka avro binary consumer with postgres config
kafka-avro-producer-topkrabbensteam (1.3.1)       - Kafka (produce messages) using Apache Avro schemas
prometheus-kafka-consumer-group-exporter (0.5.1)  - Kafka consumer group Prometheus exporter
kafka-python-log-handler (0.0.1.dev12)            - A log handler for the Python logging module, emitting logs to Kafka topics.
kafka-metrics-producer-topkrabbensteam (1.0)      - Library that can be used to produce metrics to Kafka using Apache Avro schemas
gevent-kafka (0.2)                                - ApacheKafka bindings for gevent
kafka-cffi (0.11.4a5)                             - A CFFI binding for librdkafka
kafka-tfrx (0.14.0)                               - Add a short description here!
dox-kafka (0.0.1)                                 -
kafka-transport (0.6.7)                           -
ansible-runner-kafka (0.1)                        -
kser-transport-kafka (0.1.0)                      - Kser librdkafka producer/consumer
samsa (0.3.11)                                    - Kafka Client for Kafka 0.7
azure-functions-kafka-binding (1.0.1)             -
ickafka (0.1.4)                                   - improved colored kafka
esque (0.1.4a0)                                   - A usable kafka tool.
pysubman (1.20.1.4)                               - kafka simple using
zpython-tools (0.1.1)                             - kafka tools with python
kafkaloghandler (0.9.0)                           - Kafka Logging Handler
kafka_influxdb (0.9.3)                            - A Kafka consumer for InfluxDB
dhcpkit_kafka (1.0.0)                             - Kafka extensions to DHCPKit
robinhood-aiokafka (1.0.3)                        - Kafka integration with asyncio.
aiokafka (0.5.2)                                  - Kafka integration with asyncio.
kafkaBridgeClient (0.1.5)                         - A package for using kafka-bridge to talk to kafka inside docker
kafka_store (0.1.4)                               - Kafka Store provides an easy way of archiving data from Kafka
streamsx.kafka (1.2.4)                            - IBM Streams Kafka integration
kq (2.0.0)                                        - Kafka Job Queue for Python
fjord_kafka_migration (0.2.5)                     - fjord kafka migration tools.
kafkatos3 (0.2.0)                                 - Archive kafka messages to S3
bubuku (0.10.47)                                  - AWS support for kafka broker
xoskafka (3.3.1)                                  - Wrapper around kafka for XOS
robotframework-kafkalibrary (0.0.2)               - Kafka library for Robot Framework
kser (0.8.19)                                     - Kafka serialize python library
nico (0.1)                                        - job scheduler for kafka message
kafkaesque (1.0)                                  - an easy to use kafka consumer that extends kafka-python, but follows the style of the flask server
kiel (0.9.3)                                      - Kafka client for tornado async applications.
testing.kafka (0.0.1)                             - automatically setups a kafka instance for testing
kser-crypto (0.1.4)                               - Crypto Kafka serialize python library
yelp_kafka (5.2.1)                                - A library to interact with Apache Kafka at Yelp
kafkacrypto (0.9.4)                               - Message layer security/crypto for Kafka
asynckafka (0.1.2)                                - Fast python kafka client for asyncio.
kafka_replayer (1.0.1)                            - Timestamp-based Kafka topic replayer
robotframework-confluentkafkalibrary (0.3.0)      - Confluent Kafka library for Robot Framework
kafkacli (0.0.7)                                  - Apache Kafka CLI utility tool.
klag (1.0.2)                                      - A Kafka consumer group monitoring CLI.
Kafthon (0.0.1)                                   - High level Python wrapper for Kafka
afkak (3.0.0)                                     - Twisted Python client for Apache Kafka
flasfka (1.1.6)

此处，找到我们希望安装的库是：

pip3 install kafka-python

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:10:49

pip freeze

pip freeze

用pip freeze + pip install备份和恢复Python环境

pip的常见用法之一包括：

在别处，用pip给某项目安装了相应的库之后，去freeze=冻结：

pip freeze > requirements.txt

即，把当前Python中安装的所有的库的信息，写入到一个文本文件中。

该文件文件常写成requirements.txt，表示当前Python环境所需的库的信息。

而换到另外一个地方，想要恢复之前项目的环境，则可以用：

pip install -r requirements.txt

即可自动安装所依赖的，各种Python的库，恢复了之前的项目的Python环境。

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:08:58

常见问题

pip常见问题

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:13:33

command not found pip

command not found pip

现象：用pip去安装virtualenv期间出错：

~ pip
zsh: command not found: pip

原因：当前CentOS服务器中没有安装pip

解决办法：去CentOS中安装pip

操作步骤：

先用yum安装python-pip：

yum -y install python-pip

再去升级到最新版：

pip install --upgrade pip

即可

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:12:25

Errno 13 Permission denied

Errno 13 Permission denied

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: /usr/local/man

现象：

pip3 install -r requirements.txt

报错：

  xxx git:(master) pip3 install -r requirements.txt
Collecting Django==2.0.6 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/56/0e/afdacb47503b805f3ed213fe732bff05254c8befaa034bbada580be8a0ac/Django-2.0.6-py3-none-any.whl (7.1MB)
    100% |████████████████████████████████| 7.1MB 12kB/s
Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 2))
Requirement already satisfied: pymongo==3.6.1 in /usr/local/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (3.6.1)
Collecting ipython==6.4.0 (from -r requirements.txt (line 4))
  。。。
  Running setup.py bdist_wheel for itypes … done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/7b/52/af/4e27324812e7ab7bbbc30f748d317f3739477562325cb4c723
  Running setup.py bdist_wheel for coreschema … done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/10/7b/ba/04fcd6b33e6123ca11a5f5ab56decb1a2d87ced028377a1377
Successfully built python-docx pytest-sugar simplegeneric backcall openapi-codec simplejson termcolor itypes coreschema
Installing collected packages: pytz, Django, mysqlclient, appnope, parso, jedi, simplegeneric, decorator, ptyprocess, pexpect, ipython-genutils, traitlets, wcwidth, prompt-toolkit, backcall, pickleshare, pygments, ipython, Werkzeug, django-cors-headers, djangorestframework, PyJWT, djangorestframework-jwt, uritemplate, chardet, urllib3, idna, requests, itypes, MarkupSafe, jinja2, coreschema, coreapi, openapi-codec, simplejson, django-rest-swagger, click, python-dotenv, typing, django-extensions, gunicorn, lxml, python-docx, more-itertools, atomicwrites, py, pluggy, attrs, pytest, nose, text-unidecode, python-dateutil, Faker, factory-boy, pytest-django, termcolor, pytest-sugar, raven
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/usr/local/man’
Consider using the `–-user` option or check the permissions.

原因：没有权限

解决办法：给（当前用户）加上权限，或者（通过--user）改用当前用户权限

操作步骤：

给（当前用户）加上权限

给/usr/local加上权限，或者把拥有者ower换成自己

sudo chown -R crifan /usr/local

或：

sudo chown -R $USER /usr/local

通过--user改用当前用户权限

pip3 install –-user -r requirements.txt

其他类似的问题的解决办法，也是加--user

python -m pip install -U pylint --user

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:12:31

Retrying after connection broken

Retrying after connection broken by NewConnectionError

现象：

pip install boto3

报错：

(RunningFast) ➜  stable pip install boto3
Collecting boto3
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by ‘NewConnectionError(‘<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f30c47e8710>: Failed to establish a new connection: [Errno -2] Name or service not known’,)’: /simple/boto3/
...
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by ‘NewConnectionError(‘<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f30c306b5d0>: Failed to establish a new connection: [Errno -2] Name or service not known’,)’: /simple/boto3/
  Could not find a version that satisfies the requirement boto3 (from versions: )
No matching distribution found for boto3

Failed to establish a new connection Errno -2  Name or service not known

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by ‘NewConnectionError(‘<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f30c47e8710>: Failed to establish a new connection: [Errno -2] Name or service not known’,)’: /simple/boto3/

原因：当时网络不稳定，连不上pip的源，导致报网络相关的错误

解决办法：

换个时间（网络就正常了）

此处当时就是这么做的：换了个时间，第二天早上，网络正常了，再去pip install boto3，就可以了

给pip加上代理

确保可以正常访问pip的源

如何操作，详见前面章节：给pip加代理

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:15:27

确认pip是Pyhton2还是Python3

使用pip时注意是Pyhton2还是Python3

在使用pip时，要注意pip的版本，是Python 2还是Python 3

可以通过：

pip --version

去确认当前pip到底是什么版本。

举例：

Python 2

  ➜ pip --version
  pip 10.0.1 from /Users/crifan/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)

Python 3

  ➜ pip --version
  pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

在使用时，不要搞混了。

如果搞混了，容易出现问题：

用pip安装了库（到某个Python环境=python版本）中

但是去代码中（用到了另外一个环境=Python版本）去导入对应的库，却找不到该库，import会报错。

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:13:28

不用pip安装python库

不用pip安装python库

有些python的包（第三方库），也可以不用pip，而用系统相关包管理工具去管理：

举例：

安装supervisord

CentOS

用yum

yum install supervisord

Ubuntu

用apt-get

apt-get install supervisord

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:15:40

相关

pip相关

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:14:46

pipenv

pipenv

pipenv是个Python虚拟环境管理工具。

pipenv中主要是利用pip去安装包的。

pipenv安装库有2种方式：

先进入pipenv环境，再用pip去安装库

  pipenv shell
  pip install xxx

直接用pipenv去安装

  pipenv install xxx

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:14:37

通过pip查看site-packages位置

通过pip查看site-packages位置

有时候，希望知道当前Python的site-packages的位置。

此时可以借用pip show xxx去实现。

举例：

# pip3 show Django
Name: Django
Version: 2.0.6
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD
Location: /usr/lib/python3.4/site-packages
Requires: pytz
Required-by: django-redis

从其中的：

/usr/lib/python3.4/site-packages

可以得知：

当前Python是：/usr/lib/python3.4

对应site-packages的位置是：/usr/lib/python3.4/site-packages

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:14:19

附录

附录

下面列出相关参考资料。

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:05:22

参考资料

参考资料

【已解决】macOS中全局设置pip源是ustc但是当前项目却从tsinghua的源去安装

【已解决】Mac中给pip更换源以加速下载

【已解决】macOS中pip安装powerline-status报错：WARNING Retrying Retry total 4 after connection broken by ConnectTimeoutError

【已解决】Mac中安装Python的1.7.0rc1的tensorflow

【已解决】Mac中启动PySpider

【已解决】自动抓包工具库facebook-wda优化：合并之前已优化的wda代码

【已解决】Mac中安装guesslang报错：ERROR No matching distribution found for tensorflow 1.7.0rc1 from guesslang

【已解决】windows中PyInstaller打包exe运行报错：Failed to execute script pyi_rth_pkgres ModuleNotFoundError pkg_resources.py2_warn

【已解决】树莓派中卸载重新安装Python3.7的pipenv

【已解决】树莓派升级Python3.7.3后pip出错：ImportError cannot import name main from pip

【已解决】PyCharm调试python代码import mime出错：UnicodeDecodeError ascii codec can't decode byte 0xc3 in position 7213 ordinal not in range 128

【已解决】CentOS中用pip3查看不到库kafka-python的信息

【已解决】CentOS中用python2的pip去安装supervisor后找不到/etc/supervisor中的默认配置文件supervisord.conf

【已解决】python解析excel文件并读取其中的sheet和row和column的值

【已解决】Mac本地用supervisor去管理gunicorn的Python3的Flask

【记录】用Python的Scrapy去爬取cbeebies.com

［已解决］CentOS中zsh: command not found: pip

［已解决］通过pip升级SQLAlchemy为最新的1.1版本

【已解决】python中从文件名后缀推断出MIME类型

【已解决】VSCode提示安装lint出错：Could not install packages due to an EnvironmentError Errno 13 Permission denied

【已解决】pipenv安装后警告：The script virtualenv is installed in which is not on PATH

【已解决】mac中卸载virtualenv出错：Not uninstalling virtualenv at outside environment

【已解决】Mac中把Python3的pip重新换成Python2的pip

【已解决】CentOS中如何查看Python的site-packages位置

【已解决】如何使用pip去本地安装Python的包文件

【已解决】pip3 install出错：Could not install packages due to an EnvironmentError Errno 13 Permission denied /usr/local/man

【已解决】Mac中给pip3添加代理以提升下载python包的速度 – 在路上

【已解决】pipenv虚拟环境中用pip安装pyspider出错：main.ConfigurationError: Curl is configured to use SSL, but we have not been able to determine which SSL backend it is using

【已解决】pipenv install PySpider卡死在：Locking [packages] dependencies

【已解决】Mac中升级Python 3的pipenv的版本

【已解决】Ant Design的Reactjs页面中点击下载word文件不弹框而直接下载

【已解决】Chrom中js去POST本地Django的API出错：The value of the Access-Control-Allow-Origin header in the response must not be the wildcard * when the request's credentials mode is include

【已解决】CentOS中用python2的pip去安装supervisor后找不到/etc/supervisor中的默认配置文件supervisord.conf

【已解决】CentOS中用pip或easy_install安装supervisor

【已解决】Python3中选择合适的虚拟环境工具

【记录】用VSCode开发和调试Python

【记录】Mac中安装和运行pyspider

【记录】Amazon AWS中尝试使用S3

【已解决】pip install失败：Failed to establish a new connection Errno -2 Name or service not known – 在路上

【已解决】Mac中安装selenium出错：OSError Errno 13 Permission denied /usr/local/selenium

【貌似无需解决】Mac中active后virtualenv没有生效

【已解决】pyspider运行出错：ImportError pycurl libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

【已解决】升级CentOS中的supervisor到最新版本

【已解决】用Python去连接本地mongoDB去用GridFS保存文件

【记录】安装Tensor Flow

pip vs easy_install — Python Packaging User Guide

MacOS 下利用 pyenv 管理Python 版本和虚拟环境 - 掘金

关于python Django与Flask学习的一些疑惑？ - 知乎

pypi

Which Installer is Better? Pip or Easy Install | Liquid Web

Project Summaries — Python Packaging User Guide

User Guide - pip documentation v21.2.dev0

Settings — Gunicorn 19.9.0 documentation

crifan.com，使用署名4.0国际(CC BY 4.0)协议发布 all right reserved，powered by Gitbook最后更新： 2021-04-25 20:05:26