Foreword
饭可以一日不吃,觉可以一日不睡,技术不可以一日不学。——蓝寅
python常识系列主要用陈述性举例的方式较全面的介绍一些常见、常用的python知识;
笔者编写目的可能是为了给自己做个python知识查询手册,毕竟岁数大了......
A, pip brief
- Official recommended installation and management tool for Python packages
- Download and manage Python packages
- pip in the download package while the package required will depend simultaneously downloading (convenient, strong)
Two, pip installation
Under normal circumstances, when installing python (Python 2.7.9 and later, Python 3.4 and later), will be installed by default pip
Three, pip command and its parameters introduced
# pip --help
Commands:
install 安装包.
download 下载包.
uninstall 卸载包.
freeze 按照一定的格式输出已安装包列表.
list 列出已安装包.
show 显示包详细信息.
check 检查包的依赖关系是否完整.
config 管理本地和全局配置.
search 搜索包,类似yum里的search.
wheel 根据您的需求构建wheels.
hash 计算软件包文档的哈希值.
completion 用于命令补全的助手命令.
debug 显示对调试有用的信息.
help 显示帮助文档.
General Options:
-h, --help 显示帮助.
--isolated 以隔离模式运行pip,忽略环境变量和用户配置.
-v, --verbose 更多的输出信息,最多可以使用3次.
-V, --version 显示版本并退出.
-q, --quiet 最少的输出.
--log <path> 配置详细追加日志的路径.
--proxy <proxy> 以[user:passwd@]proxy.server:port的形式指定代理
--retries <retries> 每个连接应尝试的最大重试次数(默认为5次.
--timeout <sec> 连接超时时间 (默认15秒).
--exists-action <action> 当路径已经存在时,存在-动作<</span>动作>默认动作:(s)witch,(i)gnore,(w)ipe,(b)ackup,(a)bort.
--trusted-host <hostname> 将此主机或主机:端口对标记为受信任,即使它没有有效的或任何HTTPS.
--cert <path> 替换CA bundle证书路径.
--client-cert <path> SSL客户端证书的路径,包含私钥和PEM格式证书的单个文件.
--cache-dir <dir> 将缓存数据存储在<dir>.
--no-cache-dir 禁用缓存.
--disable-pip-version-check 不要定期检查PyPI以确定是否有新版本的pip可供下载. Implied with --no-index.
--no-color 抑制彩色输出
Three, pip commonly used commands
说明:macOS上默认安装了python2的环境,你在使用pip安装包时,实际上安装到了python2环境下,怎么办?使用 pip3 即可安装到python3环境下了。
3.1 installation package
Command syntax: pip install <package name> Example:
pip install selenium
Using the above command line installation can be achieved selenium packages and their associated dependencies are automatically downloaded to the Lib> site-packages directory Python installation path, and the default install the latest version of the package, specify the version of the package for installation, use the following command :
pip install selenium==3.14.1
Which is a package version 3.14.1
3.2 uninstall package
Command syntax: pip uninstall <package name> Example:
pip uninstall selenium
3.3 List installed package
Command syntax: pip list or pip freeze For example:
pip list
pip freeze
Two commands function the same, the difference is not the same display format information
3.4 upgrade package to the latest version
Command syntax: pip install --upgrade <package name> Example:
pip install --upgrade selenium
3.5 upgrade package to the latest version
Command syntax: pip install --upgrade <package name> or pip install -U <package name> Example:
pip install --upgrade selenium
View version 3.6 update installed packages available
Command syntax: pip list --outdate or pip list -o For example:
pip list --outdate
View version 3.7 update installed packages available
Command syntax: pip list --outdate or pip list -o For example:
pip list --outdate
3.8 query contains a default package name on the mirror source (download site)
Command syntax: pip search <package name> Example:
pip search selenium
Fourth, you have not used the pip operation (continuously updated ing ...)
4.1 pip change the source installation package
Command syntax: pip install -i
pip intsall -i https://mirrors.aliyun.com/pypi/simple selenium
pip-line package mounted on a default download foreign official website address, such slow download package may be downloaded by the handover source -i parameter, pip common source:
- Tsinghua University: https: //pypi.tuna.tsinghua.edu.cn/simple
- Ali: https: //mirrors.aliyun.com/pypi/simple
- Watercress: http: //pypi.douban.com/simple/
- University of Science and Technology of China: https://pypi.mirrors.ustc.edu.cn/simple
- Huazhong University of Science: http://pypi.hustunique.com/simple
- Shandong University of Technology: http://pypi.sdutlinux.org/simple
For more information query packets 4.2
Command Syntax: pip show <package name> For example:
pip show selenium
4.3 According to requirements.txt download package to the specified directory
Command syntax: pip download --destination-directory <download store path> -r requirements.txt Example:
pip download --destination-directory /User/lanyin/software -r requirements.txt
requirements.txt files: Python project must contain a requirements.txt file, used to record all dependencies and its exact version number for the new deployment environment