# pip
# pip安装与换源
pip3 --version #检查是否安装了pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # 下载安装脚本
apt install python3-distutils
python3 get-pip.py # 运行安装脚本
pip3 install --upgrade pip # 更新
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 更改源
pip config set global.index-url https://repo.datagrand.com/repository/py/simple # 更改源
pip install <package> -i http://pypi.douban.com/simple --trusted-host pypi.douban.com # 临时使用源
pip install --no-index --find-links=./software -r requirements.txt # 从本地查找whl文件
pip config list # 查看pip配置
# 换源-修改文件
# windows
- 地址栏输入%APPDATA%
- 新建pip文件夹,在其下新建pip.ini文件
# linux:~/.pip/pip.conf或/etc/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
# pip常用指令
pip --version # 显示版本和路径
pip --help #获取帮助
pip install -U pip #升级pip
pip install SomePackage #最新版本
pip install SomePackage==1.0.4 #指定版本
pip install SomePackage>=1.0.4 #最小版本
pip install --upgrade SomePackage #升级包,通过使用==,>=, <=, >, < 来指定一个版本号
或 pip install -U SomePackage #升级包
pip uninstall SomePackage #卸载包
pip search SomePackage #搜索包
pip show #显示安装包的信息
pip show -f SomePackage #查看指定包的详细信息
pip list #列出已安装的包
pip list -o #查看可升级的包
pip freeze #查看已经安装的包以及版本信息
pip install SomePackage -i http://pypi.intra.xxx.com/simple/ --trusted-host pypi.intra.xxx.com #安装包时指定安装路径
pip install -r requirements.txt #安装指定文件中的包
##注意事项
#当python2和python3同时有pip,则使用方法如下:
python2 -m pip install xxx #python2
python3 -m pip install xxx #python3
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.
index Inspect information available from package indexes.
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 PEM-encoded CA certificate bundle. If provided, overrides the default. See 'SSL Certificate Verification' in pip documentation for more
information.
--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.