9

Yesterday I uninstalled python 3.7 version by mistake. Then I install python again (this time 3.8 version) and again set up my environment. But I could not start my Django project which has Postgres connection. Actually I cannot install "psycopg2" in my environment. I searched for hours and implement every solutions I get from online but it does not work. Let me tell you what I did so far.


  • First it said to add Postgres in my PATH so I added C:\Program Files\PostgreSQL\12\bin\ in my PATH.
  • A new problem then arise with a huge ERROR report with 2 vital Error.

    ERROR: Failed building wheel for psycopg2

    ..........................

    Running setup.py install for psycopg2 ... error

    I try to upgrade wheel but it says,

    Requirement already up-to-date

  • http://initd.org/psycopg/docs/install.html#install-from-source I learned from this site that psycopg2 requires python2 version. So I installed python 2.7 also.

  • I reinstalled PostgreSQL but it does not work.
  • I deleted my virtual environment and create again but it does not work.
  • Some says they solve this problem by running pip install psycopg2-binary But it does not work for me.

Please help me to get rid of this. I stuck for hours.

Alasdair
  • 253,590
  • 43
  • 477
  • 449
yuv
  • 360
  • 1
  • 5
  • 12

2 Answers2

11

When you asked this question, Python 3.8 had been released very recently so there were not any wheels for Python 3.8 yet.

At the time, my suggestion was to install Python 3.7.X and install the binary wheel with:

pip install psycopg2-binary

Since then, binary wheels have been released for Python 3.8, so the above command should work with Python 3.8.X as well.

I wouldn't try to build from source on Windows if it can be avoided.

Finally, you misunderstood the section of the docs about Python 2. You only need Python 2.7 if you are running Python 2. For Python 3, which you should be using for all new projects, it currently supports Python 3.4 to 3.8.

Alasdair
  • 253,590
  • 43
  • 477
  • 449
  • Thanks a lot. Oh it saves my life. I've reinstalled python 3.7 version. Now it's working. I ran `pip install psycopg2 ` and it works perfectly. Do I need to run the binary wheel now? – yuv Nov 04 '19 at 12:49
  • 1
    `pip install psycopg2` worked for you because there are [wheels for pyscopg2 2.8.4](https://pypi.org/project/psycopg2/2.8.4/#files) for Windows. If you were using a different operating system, then you would have to use `pip install psycopg2-binary` to install the wheel. Now that you have installed `psycopg2`, there is no need for you to run `pip install psycopg2-binary`. – Alasdair Nov 04 '19 at 13:09
-3

use:

sudo apt install python3-dev libpq-dev

then try doing:

pip3 install psycopg2

Hope it works for you!!