python的安装库就相当于java的lib包,下面我们把想用的安装包先安装好。

打开cmd命令:

依次输入python:

>>> import urllib
>>> import urllib.request

访问下百度试试:

>>> urllib.request.urlopen('http://www.baidu.com')

返回:<http.client.HTTPResponse object at 0x00000000030CCA20>

没有报错就说明urllib库没问题。


下面安装request库:

重新打开一个cmd,输入命令:pip3 install requests;

C:\Users\Administrator>pip3 install requests;
Collecting requestsDownloading https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d23
72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
7kB)52% |█████████████████               | 30kB 5.2kB/s eta70% |██████████████████████▋         | 40kB 6.1kB/88% |████████████████████████████▎   | 51kB100% |████████████████████████████████| 68.8kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests)

出现如上图所示,说明正在下载。

下载完成后,如下验证:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests;
>>> requests.get('http://www.baidu.com')
<Response [200]>
>>>

说明requests库已经正确安装了。


下面安装selenium库

这是用来驱动浏览器的库。

>>> import selenium
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'selenium'

在python下输入上面命令报错说明还没有安装selenium.

下面安装:

C:\Users\Administrator>pip3 install selenium
Collecting seleniumDownloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0a
e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.w
904kB)38% |████████████▎                   | 348kB 32kB/s eta 0:039% |████████████▊                   | 358kB 27kB/s eta 0:040% |█████████████                   | 368kB 29kB/s eta 0:0

下载完成后,验证如下:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD6on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium;
>>>

没有报错,说明安装成功。


下面安装chromedriver,用来在python命令启动chrome。

下载地址:http://npm.taobao.org/mirrors/chromedriver/2.28/

下载win32.

然后解压把chromedriver程序分别放到python安装目录的D:\python3.6.1\Scripts和D:\python3.6.1目录下。

然后重启一个cmd命令窗口。

输入以下命令:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 biton win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> driver -webdriver.Chrome()
Traceback (most recent call last):File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>> driver = webdriver.Chrome()DevTools listening on ws://127.0.0.1:12028/devtools/browser/24cccafd-54
357-ba79ae14af6a

并且能弹出chrome浏览器,如下:

接着输入:

>>> driver.get('http://www.baidu.com')

>>> driver.page_source  可以打开源代码。

在刚才打开的chrome浏览器中可以看到百度的网页。

说明OK。如果有报错可能会下载的chromedriver版本跟chrome流量器的版本不兼容,这就需要百度一下下了。


安装phantomjs库

这是个无界面浏览器。

下载phantomjs:  下载地址:http://phantomjs.org/download.html

下载完成后解压,进入到bin目录下,复制目录,配置环境变量。

然后启动cmd窗口,输入以下命令:

C:\Users\Administrator>phantomjs
phantomjs> console.log('hello world')
hello world
undefined
phantomjs>

安装成功。

接着执行下面命令:

>>> from selenium import webdriver
>>> driver = webdriver.PhantomJS()
>>> driver.get('http://www.baidu.com')
>>>

不会报错而且也不会弹出浏览器。


lxml库安装

C:\Users\Administrator>pip3 install lxml
Collecting lxml

如上下载lxml。

验证:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (Aon win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>>

beautifulsoup库安装

它依赖于lxml。

安装:

C:\Users\Administrator>pip3 install beautifulsoup
Collecting beautifulsoup4Downloading https://files.pythonhosted.org/pack
4883f5d23b130bc237602a1411fa670eae12351e/beautifu
94kB)43% |██████████████54% |█████████████████▍65% |████████████████████75% |████████████████████86% |████████████████████97% |████████████████████100% |████████████████████
B 41kB/s
Collecting soupsieve>=1.2 (from beautifulsoup4)

验证:

>>> from bs4  import BeautifulSoup
>>> soup =BeautifulSoup('<html></html>','lxml')
>>>

puquery 安装

它也是个网页解析库,跟jquery是一样的功能

安装命令:

C:\Users\Administrator>pip3 install pyquery
Collecting pyqueryDownloading https://files.pythonhosted.org/packages/09/c7/ce8c9c37ab8ff833
d3335c088d60bed4a35a4bed33a64f0e64fbcf29/pyquery-1.4.0-py2.py3-none-any.whl
Requirement already satisfied: lxml>=2.1 in d:\python3.6.1\lib\site-packages
om pyquery)
Collecting cssselect>0.7.9 (from pyquery)Downloading https://files.pythonhosted.org/packages/7b/44/25b7283e50585f0b
960691d951b05d061abf4a714078393e51929b30/cssselect-1.0.3-py2.py3-none-any.wh
Installing collected packages: cssselect, pyquery
Successfully installed cssselect-1.0.3 pyquery-1.4.0
You are using pip version 9.0.1, however version 19.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip'

验证命令:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (Aon win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from puquery import PyQuqery as pq
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'puquery'
>>> from pyquery import PyQuqery as pq
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ImportError: cannot import name 'PyQuqery'
>>> from pyquery import PyQuery as pq
>>> doc = pq('<html></html/>')
>>> doc =pq('<html>Hello</html>')
>>> result =doc('html').test()
Traceback (most recent call last):File "<stdin>", line 1, in <module>
AttributeError: 'PyQuery' object has no attribute 'test'
>>> result =doc('html').text()
>>> result
'Hello'
>>>

pymysql安装

它是个存储库,操作mysql

安装:

C:\Users\Administrator>pip3 install pymysql
Collecting pymysqlDownloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa
968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47k
B)42% |█████████████▊                  | 20kB 22kB/s eta 0:00:0264% |████████████████████▋           | 30kB 27kB/s eta85% |███████████████████████████▌    | 40kB 20kB100% |████████████████████████████████| 51kB25kB/s
Installing collected packages: pymysql
Successfully installed pymysql-0.9.3
You are using pip version 9.0.1, however version 19.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.

验证,这里我们先打开mysql-front,如下:

这里我有一个mysql数据库,并有个content表,里面有3条数据。

这里通过用python链接mysql并获取到这三条数据为例来验证安装的成功性:

命令如下:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> conn = pymysql.connect(host='localhost', user='root', password='root', port=
3306, db='mysql')
>>> cursor = conn.cursor()
>>> cursor.execute('select * from content')
3
>>> cursor.fetchone()
(1, '23')
>>> cursor.fetchall()
((2, '34'), (3, 'we'))

pymongo安装:

操作mongodb数据库

安装命令:

C:\Users\Administrator>pip3 install pymongo
Collecting pymongoDownloading https://files.pythonhosted.org/packages/d8/25/44b0fc81668a883739b1
08d9bd0c95b24f0b0204cb2dc93e0f259e173670/pymongo-3.7.2-cp36-cp36m-win_amd64.whl
(315kB)38% |████████████▌                   | 122kB 42kB/s eta 0:00:0542% |█████████████▌                  | 133kB 39kB/s eta 0:00:045% |██████████████▋                 | 143kB 46kB/s eta 0:00:48% |███████████████▋                | 153kB 36kB/s eta 0:0051% |████████████████▋               | 163kB 32kB/s eta 0:055% |█████████████████▊              | 174kB 24kB/s eta 0:

验证:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> client=  pymongo.MongoClient('localhost')  --链接mongo
>>> db = client['newtestdb']  --创建库
>>> db['table'].insert({'name':'Bob'})   --创建表并插入数据
ObjectId('5c51c411b1c06f1430edf124')
>>> db['table'].find_one({'name':'Boe'})
>>> db['table'].find_one({'name':'Bob'})
{'_id': ObjectId('5c51c411b1c06f1430edf124'), 'name': 'Bob'}
>>>

redis库安装:

安装命令:

C:\Users\Administrator>pip3 install redis
Collecting redisDownloading https://files.pythonhosted.org/packages/f1/19/a0282b77c23f9f9dbcc6
480787a60807c78a45947593a02dbf026636c90d/redis-3.1.0-py2.py3-none-any.whl (63kB)48% |███████████████▌                | 30kB 55kB/s eta 0:00:64% |████████████████████▋           | 40kB 44kB/s eta
0:00:01

验证命令:

C:\Users\Administrator>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r =redis.Redis('localhost',6379)
>>> r.set('name','BOB')
True
>>> r.get('name')
b'BOB'
>>>

flask库安装

C:\Users\Administrator>pip3 install flask
Collecting flaskDownloading https://files.pythonhosted.org/packages/7f/e
14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.p44% |██████████████▍                 |56% |██████████████████67% |█████████████████████▌78% |█████████████████████████89% |█████████████████████████100% |████████████████████████30kB/s

django库安装

安装命令:

C:\Users\Administrator>pip3 install django
Collecting djangoDownloading https://files.pythonhosted.org/packages/36/5
e0278c0eb71650ed9672cdc91bd5542953bec17f/Django-2.1.5-py3-3% |█                               | 245kB 11kB/s et

jupyter库安装

它类似于一个记事本的功能。

>>> pip3 install jupyter

验证:

C:\Users\Administrator>jupyter notebook
[I 00:19:41.604 NotebookApp] Writing notebook server coo
dministrator\AppData\Roaming\jupyter\runtime\notebook_co
[I 00:19:42.635 NotebookApp] Serving notebooks from loca
ministrator
[I 00:19:42.635 NotebookApp] The Jupyter Notebook is run
[I 00:19:42.636 NotebookApp] http://localhost:8888/?toke
a423c0d428289e2c0adb8b4b85
[I 00:19:42.636 NotebookApp] Use Control-C to stop thiskernels (twice to skip confirmation).
[C 00:19:42.660 NotebookApp]To access the notebook, open this file in a browser:file:///C:/Users/Administrator/AppData/Roaming/j
8480-open.htmlOr copy and paste one of these URLs:http://localhost:8888/?token=fa4befadec8ba227eb8
b4b85

同时会在浏览器上出现如下页面:

接着新建python3的一个文件:

然后

按b键又可弹出一个命令窗口,在线编辑:

打印百度网页源码:

python常用库安装相关推荐

  1. python常用库安装网址

    python常用库安装网址如下: http://pypi.python.org/pypi 转载于:https://www.cnblogs.com/it-tsz/p/9814312.html

  2. Python爬虫环境常用库安装

    Python爬虫环境常用库安装 1:urllib urllib.request 这两个库是python自带的库,不需要重新安装,在python中输入如下代码: import urllib import ...

  3. windows下python常用库的安装

    windows下python常用库的安装,前提安装了annaconda 的python开发环境.只要已经安装了anaconda,要安装别的库就很简单了.只要使用pip即可,正常安装好python,都会 ...

  4. python第三方库安装方法-Python第三方库安装

    Python有一个全球社区:https://pypi.org/,在这里我们可以搜索任何主题的Python第三方库.PyPI全称是Python Package Index,指的是Python包的索引,它 ...

  5. python常用库 自动化办公类 —— PyPDF2(处理pdf文件)

    python常用库 自动化办公类 -- PyPDF2(处理pdf文件) 摘要 PyPDF库的安装 PyPDF库的常用功能 文字提取 合并pdf文件 旋转pdf页面 pdf文件加密 摘要 本文主要介绍了 ...

  6. Python常用库 - 【持续整理归档】

    Python常用库 - [持续整理归档],比较多,会逐步慢慢细化分类和扩从python常用库.(最后更新:2020-4-8) 为方便Python开发人员进行敏捷开发,高效的完成工作需求,耗时很久整理的 ...

  7. Python第三方库安装——使用vscode、pycharm安装Python第三方库

    Python第三方库安装--使用vscode.pycharm安装Python第三方库 前言 pycharm vscode 结尾 Python基础 Python实例 前言 在这里介绍vscode.Pyc ...

  8. 抖之恒科技python常用库之工具库schema

    在Python编程语言中,有众多的开源库可以帮助程序员更加高效地完成各种任务.其中,Schema就是一款非常实用的工具库之一.本文将为您介绍Schema库的基本概念.使用方法以及它在Python编程中 ...

  9. python常用代码大全-Python常用库大全

    Python常用库大全,看看有没有你需要的. 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具 ...

最新文章

  1. Nature子刊:使用MinION快速分析早产儿肠道菌群谱并鉴定抗生素抗性致病菌
  2. 我们能从大学里学到什么
  3. 1台电脑,3个月,没有任何数据支撑!我做出了行业一线标准的识别应用
  4. 第14课:项目实战——深度优化你的神经网络模型
  5. python里面返回上一步_Python中的这3个骚操作你会吗?
  6. 使用 Angular Transfer State 的一个具体例子
  7. sketch软件_因远程协作大火的Figma,到底有多好用,会取代Sketch的地位吗?
  8. 【caffe-Windows】cifar实例编译之model的使用
  9. [EDA]FPGA/CPLD 设计流程步骤及步骤概念
  10. cf600 E. Lomsat gelral
  11. Linux 进程概念
  12. Robust line matching through line–point invariants
  13. 抹去阴影,搞定了Cyclone III
  14. nginx工作原理及配置
  15. python除法取商_python 除法
  16. winform程序:newtonsoft json 序列化时出现 “unterminated string. Excepted delimiter...
  17. 最新消息:原谷歌中国副院长刘骏任职人民搜索首席科学家
  18. 第六讲 幂级数的收敛半径和收敛域
  19. 2023云数据库技术沙龙MySQL x ClickHouse专场成功举办
  20. 动手吧,vue移动端悬浮球组件

热门文章

  1. js禁止滚动条滚动并且隐藏滚动条
  2. VB.NET CheckedListBox1操作
  3. 全方面了解接口自动化,看完还不会你锤我
  4. 手把手带你设计接口自动化测试用例:建立数据库实例和测试用例表
  5. linux scsi_id命令,linux下scsi_id和start_udev命令
  6. 根据周次显示日期范围_Power BI动态技巧,利用DAX显示最近N天的数据
  7. 记录一次office2019安装失败失败失败成功过程
  8. Unity引擎基础补充
  9. 解决使用hive打印无效INFO日志问题
  10. 【流放之路-第四章】