Python-data-access-python-postgresql-introduction

提供:Dev Guides
移動先:案内検索

Python PostgreSQL-はじめに

インストール

PostgreSQLは、強力なオープンソースのオブジェクトリレーショナルデータベースシステムです。 15年以上の活発な開発フェーズと、信頼性、データの整合性、正確性で高い評価を得ている実績のあるアーキテクチャを備えています。

Pythonを使用してPostgreSQLと通信するには、pythonプログラミング用に提供されているアダプターであるpsycopgをインストールする必要があります。現在のバージョンは psycog2 です。

psycopg2は、非常に小さく高速で、岩のように安定することを目的に書かれています。 PIP(pythonのパッケージマネージャー)で利用可能

PIPを使用したPsycog2のインストール

まず、システムにpythonとPIPが適切にインストールされていること、およびPIPが最新であることを確認してください。

PIPをアップグレードするには、コマンドプロンプトを開き、次のコマンドを実行します-

C:\Users\finddevguides>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>