【总结】Python中第三方的库(library)、模块(module),包(package)的安装方法

本文深入探讨Python的内置模块和第三方模块的区别、使用方法及安装技巧,包括常见内置模块的功能介绍、第三方模块的实例应用,以及如何通过源码或自动化工具安装第三方库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【教程】Python中的内置的模块 和第三方的模块

1.Python内置模块和第三方模块

  • 内置模块:

Python中,安装好了Python后,本身就带有的库,就叫做Python的内置的库。

内置模块,也被称为Python的标准库。

Python 2.x的在线库函数查询,可以去这里:

The Python Standard Library

  • 第三方库:

而非Python本身自带的库,就是所谓的第三方的库;

 

2.模块==库

模块,module,也常被叫做 库,Lib,Library。

 

3.常见的内置模块和第三方模块

 

Python中,一些常见的内置模块:

Python内置模块名称 功能简介 详细解释/使用示例
os 和操作系统相关 os.path — Common pathname manipulations
sys 和系统相关 sys — System-specific parameters and functions
urllib,urllib2 和网络相关 urllib — Open arbitrary resources by URL 
urllib2 — extensible library for opening URLs
re 正则表达式 re — Regular expression operations
json 处理JSON字符串 json — JSON encoder and decoder

 

更多的使用心得,可参考我的:

Python中自带模块的使用心得

 

我所折腾过的一些第三方的模块:

Python的第三方模块名称 功能简介 详细解释/使用示例
BeautifulSoup 用于解析html代码,方便提取所需内容 BeautifulSoup 
【总结】Python的第三方库BeautifulSoup的使用心得 
【整理】关于Python中的html处理库函数BeautifulSoup使用注意事项
xlwt 用于将数据写入到excel文件 【记录】Python中生成(写入数据到)Excel文件中
Scrapy 用于编写网页爬虫的框架 【记录】安装Scrapy 
【记录】折腾Scrapy的Tutorial
PIL 用于出现图像方面的图形库 【已解决】Python中通过Image的open之后,去show结果打不开bmp图片,无法正常显示图片

 

【总结】Python中第三方的库(library)、模块(module),包(package)的安装方法

提示:

【教程】Python中的内置的模块 和第三方的模块

 

Python中,想要安装第三方安装包,即third library,package等,对于熟悉的人来说,很简单。

但是对于新手,至少对于之前的我,很难,往往只是安装一个很小的包,都被搞得一头雾水。

现在略微清楚了大概逻辑了。

 

Python中第三方的库(library)、模块(module),包(package)的安装方法

方法1:下载源码,手动运行setup.py install去安装

下载对应的源码,往往都是.tar.gz,.zip的压缩包,解压后,打开windows的cmd,切换到对应目录,运行:

?
1
setup.py  install

即可去安装。

 

一些参考示例:

【记录】通过源码方式安装pip

【放弃解决】运行setup.py install去安装PyGreSQL出错:error: Unable to find vcvarsall.bat

【记录】Python中安装可以读写excel的xls文件的xlutils模块(需依赖于xlrd和xlwt)

 

方法2:利用第三方安装工具(如pip,easy_install,distribute等)去自动化安装

利用的目前常见的一些自动化安装工具,比如pip,easy_install,distribute等,自动帮你下载源码,并安装。

而且很多时候,由于要安装的包,还要依赖一些其他的别的包,而这类自动化安装工具,会自动帮你解决依赖关系,自动帮你下载并安装所缺少的那些包,所以相对来说,就省去了你的麻烦了。

Python中用pip安装模块

【记录】通过源码方式安装pip

参考:

pip Installation instructions

找到源码地址:

http://pypi.python.org/packages/source/p/pip/pip-1.0.tar.gz

下载得到pip-1.0.tar.gz,解压,然后到windows的cmd中运行setup.py install:

【已解决】Python中,运行pip install Django出错:’pip’ 不是内部或外部命令,也不是可运行的程序或批处理文件

 

解决过程】

1. 然后就去看了看,site-packages的pip和pip-1.2.1-py2.7.egg-info中,都没有pip.py或pip.exe之类的。

并且,此路径也没加到PATH中去,所以没法运行,也是正常的。

但是为何官网教程,竟然会这么写,很是奇怪。

2.后来还是无意间通过google搜:

pip’ is not recognized as an internal or external command operable program or batch file

而找到的:

Python: Pip is command is not recognized

参考其截图,去添加对应的环境变量:

E:\dev_install_root\Python27\Scripts

到PATH中去.


Python中用easy_install安装模块

【已解决】Python中使用setup.py install去安装别的模块结果出错:ImportError: No module named setuptools

 

Python中用distribute安装模块

【记录】为Python安装distribute

【记录】为Python安装MySQL数据库模块:MySQLdb


Python3.6标准 It contains data types that would normally be considered part of the “core” of a language, such as numbers and lists. For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. The library also contains built-in functions and exceptions — objects that can be used by all Python code without the need of an import statement. Some of these are defined by the core language, but many are not essential for the core semantics and are only described here. The bulk of the library, however, consists of a collection of modules. There are many ways to dissect this collection. Some modules are written in C and built in to the Python interpreter; others are written in Python and imported in source form. Some modules provide interfaces that are highly specific to Python, like printing a stack trace; some provide interfaces that are specific to particular operating systems, such as access to specific hardware; others provide interfaces that are specific to a particular application domain, like the World Wide Web. Some modules are available in all versions and ports of Python; others are only available when the underlying system supports or requires them; yet others are available only when a particular configuration option was chosen at the time when Python was compiled and installed. This manual is organized “from the inside out:” it first describes the built-in functions, data types and exceptions, and finally the modules, grouped in chapters of related modules. This means that if you start reading this manual from the start, and skip to the next chapter when you get bored, you will get a reasonable overview of the available modules and application areas that are supported by the Python library. Of course, you don’t have to read it like a novel — you can also browse the table of contents (in front of the manual), or look for a specific function, module or term in the index (in the back). And finally, if you enjoy learning about random subjects, you choose a random page number (see module random) and read a section or two. Regardless of the order in which you read the sections of this manual, it helps to start with chapter Built-in Functions, as the remainder of the manual assumes familiarity with this material.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值