Python-FAQ-pip
·
1 需求
2 接口
D:\Python310\Scripts>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.
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.
3 设置清华源
临时使用
安装单个库时,通过 -i 参数指定清华源:
pip install 库名 -i https://pypi.tuna.tsinghua.edu.cn/simple
永久设置
方法 1:命令行设置
打开命令提示符(Windows)或终端(Mac/Linux),执行以下命令:
# 设置清华源为默认源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
方法 2:手动创建配置文件
-
Windows 系统:
- 在文件夹地址栏输入
%APPDATA%并回车,进入应用数据目录 - 新建
pip文件夹,在其中创建pip.ini文件 - 打开
pip.ini并写入以下内容:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = pypi.tuna.tsinghua.edu.cn
- 在文件夹地址栏输入
3 pip设置代理
思路1:
pip config set global.proxy http://proxyhk.zte.com.cn
思路2:
# HTTP代理
pip install pypubsub --proxy http://代理服务器地址:端口号
# HTTPS代理
pip install pypubsub --proxy https://代理服务器地址:端口号
# 如果代理需要用户名和密码认证
pip install pypubsub --proxy http://用户名:密码@代理服务器地址:端口号
3 pip安装卸载三方库
pip安装三方库
- pip install package
pip安装指定版本的三方库
- pip install package==1.0.4
pip卸载三方库
- pip uninstall package
pip更新三方库
- pip install --upgrade package
4 参考资料
更多推荐
所有评论(0)