Python库的使用说明

1 第三方库索引网站

the Python Package Index,PyPI
该页面提供了9万多个Python的第三方库的信息和下载方式。

2 第三方安装

2.1 pip工具介绍

  pip3 是Python官方提供并维护的在线第三地方库安装工具。对于同时安装 Python2Python3 环境系统,建议采用pip3命令专门为 Python3 版本安装第三方库。
  pip3支持安装(install)、下载(download)、卸载(uninstall)、列表(list)、查看(show)、查找(search)等一系列安装和维护子命令。

2.2 pip工具安装

打开CMD命令窗口,以安装jieba库为例,输入一下代码:

pip3 install jieba

回车等待。
安装过程↓↓↓
在这里插入图片描述

安装完成↓↓↓
在这里插入图片描述

2.2.1 list 命令查看已安装的库列表

通过 list 命令可以查看系统中已经安装的第三的库文件。

pip3 list

2.2.2 uninstall 命令

通过 uninstall 命令可以卸载系统中已经安装的第三的库文件。

命令示例(以卸载jieba库为例):

pip3 uninstall jieba

命令执行完成后需要手动输入确认字符,才可以完成卸载。
在这里插入图片描述

2.2.3 show 命令

列出某个已经安装库的详细信息。
命令示例(以jieba库为例):

pip3 show jieba

2.2.4 download 命令

download 命令可以下载第三方库的安装包,但是并不安装。
命令示例(以jieba库为例):

pip3 download PyQt5

2.2.5 search 命令

search 命令可以联网搜索库名或摘要中的关键字。

pip3 search  installer

2.3 文件安装

  由于Python某些第三方库仅提供源代码,通过pip下载文件后无法在Windows系统编译安装,会导致第三方库安装失败。在Windows平台下所遇到的无法安装第三方库的问题大多属于这类。
  为了解决这类第三方库安装问题,美国加州大学尔湾分校提供了一个页面,帮助Python用户获得Windows可直接安装的第三方库文件,链接地址如下:链接直达

安装步骤
首先,在第三库官网获取后缀为.whl的库文件。
假设把下载的文件放在D:\ku 目录下,文件名称为:scipy-0.18.1-cp35m-win_amd64.whil
最后再执行命令

pip install D:\ku\scipy-0.18.1-cp35m-win_amd64.whil

2.4 自定义安装

是对于上述没有安装成功的第三方库,需要根据第三方库主页的指示步骤进行安装使用。

3 常用的第三方库

注:一些库在安装指令中使用名字与库名字并不一致。

库名用途pip安装指令
NumPy矩阵运算pip3 install numpy
atplotlib产品级2D图形绘制pip3 install matplotlib
PIL图像处理pip3 install pillow
sklearn机器学习和数据挖掘pip3 install sklearn
RequestsHTTP协议访问pip3 install requests
Jieba中文分词pip3 install jieba
Beautiful Soup或bs4HTML和XML解析pip3 install beautifulsoup4
WheelPython文件打包pip3 install wheel
pyinstaller打包Python源文件为可执行文件pip3 install pyinstaller
DjangoPython最流行的Web开发框架pip3 install django
Flask轻量级Web开发框架pip3 install flask
WeRoBot微信机器人开发框架pip3 install werobot
Networkx复杂网络和图结构的建模和分析pip3 install networkx
SymPy数学符号计算pip3 install sympy
pandas高效数据分析pip3 install pandas
PyQt5基于Qt的专业级GUI开发框架pip3 install pyqt5
PyOpenGL多平台OpenGL开发接口pip3 install pyopengl
PyPDF2PDF文件内容提取及处理pip3 install pypdf2
docoptPython命令行解析pip3 install docopt
PyGame简单小游戏开发框架pip3 install pygame

4 库的引用方法

4.1 第一种

import <库名字>
示例:

import turtle

4.2 第二种

from <库名> import <函数名,函数名,…,函数名>
from <库名> import * *是通配符,表示所有函数

from tutrle import setup,penup
from turtle import *

4.2 第三种

对于特别大的第三方库,例如lxml它既能处理xml的数据,又能处理html的数据,于是这种库会划分子模块,lxml.html模块专门负责html相关的数据。
程序示例:

from sklearn.linear_model import LogisticRegression

4.3 as 保留字

as 保留字与import 一起使用能够改变后续代码中库的命名空间,有助于提高代码的可读性。

import numpy as np

参考资料

[1] 嵩天,礼欣,黄天羽.Python语言程序设计基础.第2版.北京:高等教育出版社,2017

Python is an extensible, interpreted, object-oriented programming language. It supports a wide range of applica- tions, from simple text processing scripts to interactive Web browsers. Python 是一种可扩展的, 即译式, 面向对象规格的编程语言. 它能应用在极广泛的地方, 从简单的文字处理 工作到交互式的网页浏览器. While the Python Reference Manual describes the exact syntax and semantics of the language, it does not describe the standard library that is distributed with the language, and which greatly enhances its immediate usability. This library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs. Python 语言参考手册 中精确地描述了Python 语言的句法及语义. 然而语言参考手册中没有提到Python 所 附带功能强大的标准. 这个函式大大地增强了Python 的实用性. 其中包括C 写的内建模组, 提供介面 让程式进行操作系统层次的工作, 例如档案的输出输入; 同时也有以Python 语言本身编写的模组, 为实际 编程时常遇的问题提供标准解决方案. 这类模组有的经过特别设计以便Python 程式在跨平台的情况下运 行无误. This library reference manual documents Python’s standard library, as well as many optional library modules (which may or may not be available, depending on whether the underlying platform supports them and on the configuration choices made at compile time). It also documents the standard types of the language and its built-in functions and exceptions, many of which are not or incompletely documented in the Reference Manual. 本参考手册罗列并说明Python 标准的各种功能, 以及许多非核心的模组(按不同的操作系统和编译时 的设置而定, 不是每台机上的Python 都能用这些模组.) 本手册同时记载了Python 语言所有的标准数据类 型, 内建函数, 异常类, 这些在参考手册中被忽略了或只是扼要的提过一下. This manual assumes basic knowledge about the Python language. For an informal introduction to Python, see the Python Tutorial; the Python Reference Manual remains the highest authority on syntactic and semantic questions. Finally, the manual entitled Extending and Embedding the Python Interpreter describes how to add new extensions to Python and how to embed it in other applications. 本手册的读者要对Python 有基本的认识. 初学者应该从Python 指南 开始. 至于Python 语言参考手册 则是该语言的语法和语义问题上的权威阐释. 最后 扩展或嵌入 Python 解释器 一文解说了如何在Python 中加入新的扩展模组; 以及怎样把Python 解释器嵌入到其他的应用程式中.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

驽马同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值