PIP就是 Python标准库(The Python Standard Library)中的一个包,这个包比较特殊,是The Python Packaging Authority (PyPA) 推荐的 Python 包管理工具(The Python Packaging Authority (PyPA) is a working group that maintains many of the relevant projects in Python packaging)。PIP支持从PyPI(The Python Package Index (PyPI) is a repository of software for the Python programming language),本地项目以及直接从分发文件进行安装。pip是一个命令行程序。
目前pip是被默认集中在python中的,因此默认安装。
1、pip 后不跟 install
pip最为常见的命令是install,但是除此之外pip也有许多其他命令;在此我们先对其他命令进行总结。在命令行中键入:pip+ 回车,就会出现许多有关于pip的说明。
freeze
pip freeze,查看已经安装的包及版本信息。可使用 “ > ”导出到指定文件中。
list
列出当前已经安装的包。使用命令pip list -o 则可查询可升级的包。
show
显示包所在目录及信息,格式为:pip show <包名>。
search
搜索包,格式为:pip search <搜索关键字>。关键字不需要为完整的包名,可以是包名当中含有的特殊字段。
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.
2、pip 所接为install相关
pip 后面所接为install 或者 uninstall时,可以使用的参数等显著增多,较其他命令行显然多处许多。
常用命令:
-i:指定库的安装源 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -U funcat
pip install SomePackage # 最新版本
pip install SomePackage==1.0.4 # 指定版本
pip install SomePackage>=1.0.4 # 最小版本
pip install -U <包名> 或:pip install <包名> --upgrade 升级 原来已经安装的包,带上U才会更新到最新版本。
sudo pip install --upgrade --no-deps --force-reinstall <包名> --upgrade和–force-reinstall确保重新安装,而–no-deps避免重新安装依赖项。
pip install --ignore-installed <包名> 如果已有的包想要忽略已安装的包,而不进行重新安装。
以下是pip常见的一些命令,在实际使用中经常会遇到。
-r, --requirement <file> Install from the given requirements file. This
option can be used multiple times.
--no-deps Don't install package dependencies.
--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.
-U, --upgrade Upgrade all specified packages to the newest
available version. The handling of dependencies
depends on the upgrade-strategy used.
--force-reinstall Reinstall all packages even if they are already
up-to-date.
-I, --ignore-installed Ignore the installed packages (reinstalling
instead).
Package Index Options:
-i, --index-url <url> Base URL of 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.
-f, --find-links <url> If a url or path to an html file, then parse for
links to archives. If a local path or file://
url that's a directory, then look for archives
in the directory listing.