PIP Install Psycopg2 – PIP Install Postgres – Python Postgres Installation

This is how you connect your Python App with a PostgreSQL Database System

If you need to save some data for your Python project then you might have come across several database libraries for Python, like:

1. SQLite

2. MySQL

3. PostgreSQL

4. And many more Python databases.

SQLite is a lightweight database as you can guess from its name as well. It is great for beginners & fine for small projects. But if you really care about the security and scalability of your database then MySQL, Postgres & similar production level database management system.

It is entirely up to you when choosing a database system but if you are going the SQL route then you will find many of these database systems quite similar to use, at least as far as querying the data goes.

Because the underlying query language would be SQL.

In my complete Flask tutorial series, I’ve shown both ways…SQLite & PostgreSQL.

This article is one of the many articles on PIP Install (libraries/modules) because I’ve seen coders get confused & need very specific guide.

First of all 👇

In this article, I am going to take you step by step on how to pip install Psycopg2 (which installs Postgres adapter for Python) and then, we’ll look at how to connect to Postgresql.

Check PIP Installation via pip –version

If pip is not present then you can checkout this article on 🔗PIP Installation in Windows.

So, now let’s begin installation of Psycopg2: 🪜

  1. Open command prompt or power shell via either searching it in start menu or press 🪟+R key to open run command dialog box.
  2. Type ‘cmd’ & hit Enter.
  3. Now, create a new folder with the name of your choice.
  4. Go into that folder via cd folder-name.
  5. Now, type this: ⌨️python -m venv env
  6. Above command is to create a virtual environment so that your libraries can be installed separately from rest of your Python libraries.
  7. Now, type this: ⌨️ env\Scripts\activate
  8. Your virtual environment will now be active.
  1. If you want to install psycopg2 globally, then skip step 3 to 7. Further commands are applicable for both methods.
  2. Now type this: ⌨️pip install psycopg2.
  3. As you can see in the image, that if there are no issues, the installation will happen in seconds.

How to check for successful installation of psycopg2?

  • This is even simpler. I hope you are still in the command prompt shell.
  • Now type: ⌨️ python & hit Enter key.
  • You’ll now be working in Python shell 🐍.
  • Now type: import psycopg2 & hit Enter key.
  • If you do not see any errors, then the installation was successful.
  • Take a look at the image below to see an example code.
  • 🛑Make sure to install PGAdmin4 as well via following this link, 🔗Download PGAdmin 4.

Thanks for Reading. 📖

🎥Make sure to Watch the PIP Install Psycopg2 Tutorial Below. It will help you understand the process better.

Resources:

Download Python Latest Version

Download Python Packages

Subscribe to Code Jana Youtube Channel

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top