1、更换pip镜像源

国内的一些pip镜像

# 豆瓣
https://pypi.doubanio.com/simple/
# 阿里云    
https://mirrors.aliyun.com/pypi/simple/
# 清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/

临时使用

pip install some-package -i https://mirrors.aliyun.com/pypi/simple/

设为默认

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple

配置文件
Ubuntu:~/.config/.pip/pip.conf
Windows:C:\Users\DH\AppData\Roaming\pip\pip.ini

# vim ~/.config/.pip/pip.conf
[global]
  index-url = https://mirrors.aliyun.com/pypi/simple

缓存存储目录
Linux and Unix

~/.cache/pip 

OS X

~/Library/Caches/pip

Windows

%LocalAppData%\pip\Cache

2、pip3管理扩展库

pip3文档:https://pip3.pypa.io/en/stable/quickstart/
模块安装路径

  • 保存在../Lib/site-packages/,导入模块后,输入模块名可查看模块所在路径。

版本问题

  • pip(Python 2.x),pip3(Python 3.x)

将pip3(在Scripts文件夹中)添加到环境变量中(或转到pip3所在目录),在cmd中执行以下命令

  • pip3 download SomePackage[==version],下载扩展库的指定版本,不安装
  • pip3 freeze [> requirements.txt],以requirements的格式列出已安装模块Package==version
  • pip3 list,列出当前已安装的所有模块
  • pip3 install SomePackage[==version],在线安装SomePackage模块的指定版本
  • pip3 install package1 package2 ...,依次(在线)安装package1、package2等
  • pip3 install -r requirements.txt,安装requirements.txt文件所指定的扩展库
  • pip3 install --upgrade SomePackage,升级SomePackage模块
  • pip3 uninstall SomePackage[==version],卸载SomePackage模块的指定版本
  • pip3 show SomePackage,显示库信息

pip3更新:不需要时刻关注,如有更新,使用时会有提醒
python -m pip3 install --upgrade pip3

国外网站上有最新版本的库,在线安装速度较慢,可能会因为网络问题中断,导致安装失败。将库文件下载下来再安装,是最稳妥的办法。尤其是对于比较大的框架,在线安装方式失败概率很高。

3、wheel安装扩展库(推荐用这种方式)

到PyPI上下载对应的wheel文件,针对版本下载,若无版本,十有八九有问题。
或者用pip3 download SomePackage[==version],下载扩展库的指定版本,不安装
在命令行界面进入对应wheel文件目录,利用pip3安装
pip3 install filename.whl

4、源码安装扩展库

找到库的源码地址,并用命令下载
git clone url
curl -OL url
命令安装
cd package路径
python setup.py install

5、验证安装(非常有必要)

进入python运行环境,import Package,(输入模块名,可显示所在路径)

posted on 2020-04-10 20:27  木鱼与琴  阅读(343)  评论(0)    收藏  举报