1

I am using imports :- import psycopg2

But while running the code in local, I am facing an issue of :-

from psycopg2._psycopg import (

ModuleNotFoundError: No module named 'psycopg2._psycopg'

I have installed psycopg2 using cmd [pip install psycopg2] psycopg2 version 2.8.4 python version 3.7.3 python 3.7 32bit

How should I import the ._psycopg.py file in windows? or any other solution if possible?

Anukriti
  • 11
  • 1
  • 2
  • Does this answer your question? [ImportError: No module named 'psycopg2.\_psycopg'](https://stackoverflow.com/questions/36103034/importerror-no-module-named-psycopg2-psycopg) – Mr.Dark Apr 03 '20 at 06:41
  • No . I have already seen it but none is working. However how can i see which psycopg2 version is enabled for python 3.7 32 bit ? – Anukriti Apr 03 '20 at 06:55
  • Try `pip install psycopg2-binary` – Mr.Dark Apr 03 '20 at 07:02
  • Try using that. Go here:http://www.stickpeople.com/projects/python/psycopg/&ved=2ahUKEwjYw7zJ2MvoAhUnzzgGHTm0CFMQFjABegQIBxAB&usg=AOvVaw1k6ZJ3IHLTZwmVObfXCIll – Mr.Dark Apr 03 '20 at 07:02
  • same error with psycopg2-binary also !! – Anukriti Apr 03 '20 at 07:29
  • Did you try get what you want from http://www.stickpeople.com/projects/python/psycopg/&ved=2ahUKEwjYw7zJ2MvoAhUnzzgGHTm0CFMQFjABegQIBxAB&usg=AOvVaw1k6ZJ3IHLTZwmVObfXCIll – Mr.Dark Apr 03 '20 at 07:46

1 Answers1

2

I'm also facing the same problem. It took me 2 days to pulled out my hair until I found the solution.

What I've been tried

Here's what I have been doing to solve this issue BUT DIDN'T SOLVE THE PROBLEM. I hope it will help anybody else who has the same problem.

  1. Install "psycopg2" and "psycopg2-binary"
    • pip install psycopg2
    • pip install psycopg2-binary
  2. Install "libpq-dev"
    • sudo apt install libpq-dev
  3. Install "python-psycopg2" and "python3-psycopg2"
    • sudo apt install python-psycopg2 python3-psycopg2
  4. Install "python-dev" and "python3-dev" and "python3.9-dev"
    • sudo apt install python-dev python3-dev python3.9-dev
  5. Install "python-setuptools"
    • sudo apt install python-setuptools

Unfortunately, none of my effort above solve my problem.


What's the solution

So, here's my solution that I've been try and IT WORKS

Install the latest mod_wsgi from Github.

You should install this latest 'mod_wsgi' in order to your wsgi able to use Psycopg2 library. Here's my step to do it :

  1. Go to release page mod_wsgi on Github (https://github.com/GrahamDumpleton/mod_wsgi/releases)
  2. Download the file from latest version. As I write this, the latest version is 4.7.1 (https://github.com/GrahamDumpleton/mod_wsgi/archive/4.7.1.tar.gz)
  3. Follow the installation guide from official docs.
    1. Unpacking source code
      • tar xvfz mod_wsgi-4.7.1.tar.gz
    2. Configure source code
      • ./configure
    3. Build the source code and install
      • make
      • make install
    4. Restart apache server
      • sudo service apache2 restart

This solution has works on my machine (Ubuntu 18.04 & Python 3.9 Venv).


Alternative solution

Here's some solution from others.

  1. Saray Chak's solution
Dharman
  • 30,962
  • 25
  • 85
  • 135
ibnɘꟻ
  • 830
  • 13
  • 15