1、第三方库
(1)第三方库:https://pypi.org/
(2)PyPI
-PyPI:Python Package Index
-PSF维护的展示全球Python计算生态的主站,学会检索并利用PyOI,找到合适的第三方库开发程序
实例:在pypi.org搜索XXX,挑选合适开发目标的第三方库作为基础,完成自己需要的功能
2、第三方库的安装方法
(1)pip安装方法 使用pip安装工具(命令行下执行)
pip -h 打开命令帮助信息
pip install -U <第三方库名> 使用-U标签更新已安装的指定第三方库
pip uninstall <第三方库名> 卸载指定的第三方库
pip download <第三方库名> 下载但不安装指定的第三方库
pip show <第三方库名> 列出某个指定第三方库的详细信息
pip search <关键词> 根据关键词在名称和介绍中搜索第三方库
pip list 列出当前系统已经安装的第三方库
C:\Users\lenovo>pip -h
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.
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.
--no-color Suppress colored output
(2)集成安装方法 Anaconda https://www.continuum.io
支持近800个第三方库,包含多个主流工具,适合数据计算领域开发
(3)文件安装方法
为什么有些第三方库用pip可以下载,但无法安装?
-某些第三方库pip下载后,需要编译再安装;如果操作系统没有编译环境,则能下载但不能安装。
-https://www.lfd.uci.edu/~gohlke/pythonlibs/ UCI页面 补丁安装,提供编译后的版本
在UCI页面上搜索wordcloud,下载对应版本的文件,使用pip install <文件名> 安装
3、第三方库自动安装脚本
库名 | 用途 | pip安装指令 |
NumPy | N维数据表示和运算 | pip install numpy |
Matplotlib | 二维数据可视化 | pip install matplotlib |
PIL | 图像处理 | pip install pillow |
Scikit-Learn | 机器学习和数据挖掘 | pip install sklearn |
Requests | HTTP协议访问及网络爬虫 | pip install requests |
jieba | 中文分词 | pip install jieba |
Beautiful Soup | HTML和XML解析器 | pip install beautiful soup |
Wheel | Python第三方库文件打包工具 | pip install wheel |
PyIstaller | 打包Python源文件为可执行文件 | pip install pyinstaller |
Django | Python最流行的Web开发框架 | pip install django |
Flask | 轻量级Web开发框架 | pip install flask |
WeRoBot | 微信机器人开发框架 | pip install werobot |
SymPy | 数学符号计算工具 | pip install sympy |
Pandas | 高效数据分析和计算 | pip install pandas |
Networkx | 复杂网络和图结构建模和分析 | pip install networkx |
pyQt5 | 基于Qt的专业级GUI开发框架 | pip install pyqt5 |
PyOpenGL | 多平台OpenGL开发接口 | pip install yopengl |
PyPDF2 | PDF文件内容提取及处理 | pip install pypdf2 |
docopt | Python命令行解析 | pip install docopt |
PyGame | 简单小游戏开发框架 | pip install pygame |
#自动安装第三方库
import os
libs = {"sklearn","requests","jieba","beautifulsoup4",\
"wheel","networkx","sympy","django","flask","weobot",\
"pyqt5","pandas","pyopengl","pypdf2","docopt","pygame"}
try:
for lib in libs:
os.system("pip install" + lib)
print("Successful")
except:
print("Failed Somehow")