文章目录
换源
第一件事当然是换源 ~
pip 国内的一些镜像
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
修改源方法:
临时使用:
可以在使用pip的时候在后面加上-i参数,指定pip源
eg: pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改:
LInux系统
修改 ~/.pip/pip.conf
(没有就创建一个), 内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Windows:
win+R 打开用户目录%HOMEPATH%,在此目录下创建 pip 文件夹,在 pip 目录下创建 pip.ini 文件, 内容如下:
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
conda 换源
添加清华的镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda - -help // 找到配置文件.condarc 的路径 ,将上述显示的配置信息中 - defaults 所在行删除保存即可
查看源:
conda config --show channels
换回默认源
conda config --remove-key channels
用法总览
pip3 --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.
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.
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.
--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 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.
一、安装 & 移除
安装指定包的最新版
pip3 install pkg_name
安装制定包的指定版本
pip3 install pkg_name==version
$ pip3 install django==2.0.5
移除指定包
pip3 uninstall pkg_name
在 PyPI 上模糊查找相关包
pip3 search pkg_name
二、查看相关
查看所有已安装的包
pip3 list
形如:
amqp (1.4.9)
anyjson (0.3.3)
asn1crypto (0.24.0)
查看指定包的相关信息
pip3 show pkg_name
$ pip3 show django
Name: Django
Version: 2.1.4
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: /home/ezreal/.local/lib/python3.6/site-packages
Requires: pytz
三、更新相关
更新 pip
在 Anaconda prompt 环境下
conda upgrade pip
普通环境
python -m pip install --upgrade pip
更新包
检查哪些包需要更新
pip list --outdated
更新指定包
pip install --upgrade pkg_name
四、freeze 的使用
列出所有已安装包
pip3 freeze
形如:
vine==1.1.4
virtualenv==16.1.0
youtube-dl==2018.9.10
生成 requirements.txt 文件
- 将当前 Python 环境下所有类库导出生成为 requirements.txt
pip3 freeze > requirements.txt
- 将特定项目使用的类库导出生成为 requirements.txt(其中.为当前文件夹下的项目,可改成你项目的路径)
# 需要安装第三方库
pip3 install pipreqs
# .表示当前目录
pipreqs . --encoding=utf8
- 安装 requirements.txt 依赖
pip3 install -r requirements.txt
五、遇到的异常及解决
PermissionError: [WinError 5] 拒绝访问
解决:加上--user
参数
pip install --user --upgrade tensorflow-gpu
REFERENCES
[1] PIP 更换国内安装源:https://blog.csdn.net/yuzaipiaofei/article/details/80891108