Python 数据访问教程

Python 数据访问 - 主页

Python MySQL

Python MySQL - 简介 Python MySQL - 数据库连接 Python MySQL - 创建数据库 Python MySQL - 创建表 Python MySQL - 插入数据 Python MySQL - 选择数据 Python MySQL - Where 子句 Python MySQL - 排序 Python MySQL - 更新表 Python MySQL - 删除数据 Python MySQL - 删除表 Python MySQL - Limit 子句 Python MySQL - 连接 Python MySQL - 游标对象

Python PostgreSQL

Python PostgreSQL - 简介 Python PostgreSQL - 数据库连接 Python PostgreSQL - 创建数据库 Python PostgreSQL - 创建表 Python PostgreSQL - 插入数据 Python PostgreSQL - 选择数据 Python PostgreSQL - Where 子句 Python PostgreSQL - 排序 Python PostgreSQL - 更新表 Python PostgreSQL - 删除数据 Python PostgreSQL - 删除表 Python PostgreSQL - Limit 子句 Python PostgreSQL - 连接 Python PostgreSQL - 游标对象

Python SQLite

Python SQLite - 简介 Python SQLite - 建立连接 Python SQLite - 创建表 Python SQLite - 插入数据 Python SQLite - 选择数据 Python SQLite - Where 子句 Python SQLite - 排序 Python SQLite - 更新表 Python SQLite - 删除数据 Python SQLite - 删除表 Python SQLite - Limit 子句 Python SQLite - 连接 Python SQLite - 游标对象

Python MongoDB

Python MongoDB - 简介 Python MongoDB - 创建数据库 Python MongoDB - 创建集合 Python MongoDB - 插入文档 Python MongoDB - 查找 Python MongoDB - 查询 Python MongoDB - 排序 Python MongoDB - 删除文档 Python MongoDB - 删除集合 Python MongoDB - 更新 Python MongoDB - Limit 子句

Python 数据访问资源

Python 数据访问 - 快速指南 Python 数据访问 - 有用资源 Python 数据访问 - 讨论


Python PostgreSQL - 简介

安装

PostgreSQL 是一个功能强大的开源对象关系数据库系统。它拥有超过 15 年的活跃开发阶段和经过验证的架构,在可靠性、数据完整性和正确性方面赢得了良好的声誉。

要使用 Python 与 PostgreSQL 通信,您需要安装 psycopg,这是为 Python 编程提供的适配器,其当前版本为 psycog2

psycopg2 的编写目标是非常小巧、快速且稳定如磐石。它可以在 PIP(python 的包管理器)下使用

使用 PIP 安装 Psycog2

首先,确保 python 和 PIP 已正确安装在您的系统中,并且 PIP 是最新的。

要升级 PIP,请打开命令提示符并执行以下命令 −

C:\Users\Tutorialspoint>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.0.3
Uninstalling pip-19.0.3:
Successfully uninstalled pip-19.0.3
Successfully installed pip-19.2.2

然后,以管理员模式打开命令提示符并执行pip install psycopg2-binary命令,如下所示 −

C:\WINDOWS\system32>pip install psycopg2-binary
Collecting psycopg2-binary
Using cached https://files.pythonhosted.org/packages/80/79/d0d13ce4c2f1addf4786f4a2ded802c2df66ddf3c1b1a982ed8d4cb9fc6d/psycopg2_binary-2.8.3-cp37-cp37m-win32.whl
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.3

验证

要验证安装,请创建一个包含以下行的示例 Python 脚本。

import mysql.connector

如果安装成功,则执行时不会出现任何错误 −

D:\Python_PostgreSQL>import psycopg2
D:\Python_PostgreSQL>