[Django]-Django 'pip install django-heroku'(psycopg2) error is blocking deployment to Heroku

0πŸ‘

βœ…

I tested the same steps on windows 10 and everything pass with flying colors and I was able to deploy to heroku.

It seems like this might be MAC OS Mojave specific.

MacOS Mojave 10.14.6 was the version I had an issue with

Solution for me was to deploy through windows 10 or downgrade to a older Mac OS such as High Sierra.

πŸ‘€sudoxx

42πŸ‘

I have tried several solutions, none worked except simplest solution:

pip3 install psycopg2==2.7.5

this command worked perfectly (seems like a problem with a version)

πŸ‘€Artur

32πŸ‘

To install heroku in django the command line django-heroku changed to

pip install django-on-heroku  
πŸ‘€Flaco13

13πŸ‘

For MacOS users

After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :

Install openssl with

brew install openssl

if you don’t have it already.
add openssl path to LIBRARY_PATH :

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

install psycopg2 with pip

pip3 install psycopg2

I was searching and this finally worked for me.

πŸ‘€Sudip Kandel

6πŸ‘

do this and it will work

  1. brew install postgresql
  2. pip3 install psycopg2
  3. pip install django-heroku

4πŸ‘

I have had the same issue and kept wondering why Heroku had not updated the package django-heroku package to fix this. However we should not expect updates to fix this. The django-heroku repo has been achieved on github. https://github.com/heroku/django-heroku.
Closer look at https://github.com/heroku/django-heroku/blob/master/setup.py will show you they listed psycopg2 as a requirement. Hence why it tries to install on your computer.
Solution to this.

 1. Remove django-heroku package from your requirements.
 2. Remove django-heroku settings from settings.py
 3. Set STATIC_ROOT.
 4. Add your heroku url to ALLOWED_HOSTS.

Django-heroku is no longer needed to host Django applications on heroku. I have tested the above with an application running on DJango 2.2.

πŸ‘€Arthur Nangai

3πŸ‘

Recently ran into the issue .
What helped me is pip3 install psycopg2==2.8.3 and later on pip3 install django-heroku

2πŸ‘

From docs
For most operating systems, the quickest way to install Psycopg is using the wheel package available on PyPI:

$ pip install psycopg2-binary

This will install a pre-compiled binary version of the module which does not require the build or runtime prerequisites.

you should get such a response

Collecting psycopg2-binary
  Downloading psycopg2_binary-2.8.6-cp38-cp38-manylinux1_x86_64.whl (3.0 MB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 3.0 MB 62 kB/s 
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6

πŸ‘€griffins

1πŸ‘

OS: MacOS Mojave 10.14.4

virtualenv: python3.6

I’m not using heroku but was getting the same error and this is what fixed it for me:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

after that you should be able to install via pip:

(venv) MacBook-Pro:testing_django user$ pip install psycopg2
(venv) MacBook-Pro:testing_django user$ pip freeze
Django==2.2.4
psycopg2==2.8.3
pytz==2019.2
sqlparse==0.3.0

from: https://github.com/python-pillow/Pillow/issues/3438#issuecomment-435169249

πŸ‘€kt-0

1πŸ‘

I had the same issue for a while then this helped me:

brew install openssl

Add openssl path to LIBRARY_PATH:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

Install psycopg2 with pip:

pip3 install psycopg2

then finally:

pip3 install django-heroku
πŸ‘€jmcb

1πŸ‘

In linux,try

sudo apt install libpq-dev

pip install django-heroku

I solved my issue using these commands

if it is not working,try

sudo apt install django-on-heroku

πŸ‘€Sanju P K

1πŸ‘

pip install django-on-heroku changed psycopg2 to psycopg2-binary so it works and is installable!

πŸ‘€paul iyinolu

0πŸ‘

You will need to install postgres db, postgres client and libpq-dev via os commands
Then you can install below in python environ

pip install psycopg2

For more details look at http://initd.org/psycopg/docs/install.html

πŸ‘€Shirish Goyal

0πŸ‘

Update: Oct.12.2021

Same solution as @Artur offered but I had to change the version to

pip3 install psycopg2==2.9 
πŸ‘€almo

0πŸ‘

You can use this brew install postgresql to install packages with the correct wheel file. When a venv is activated, sometimes you need to download the correct wheel file to install certain packages. This installation uses setup.py install instead making it easy for the virtual environment to install the desired package using the pip3 installation. Another common package that requires this installation is scikit-learn.

brew install postgresql
pip3 install psycopg2
pip3 install django-heroku
πŸ‘€tandamangreen

0πŸ‘

In my case, I was missing sudo apt-get install python3-dev. I already had psycopg2-2.9.3 but this then enabled pip install django-heroku to compile correctly.

πŸ‘€jjjshade

0πŸ‘

pip install psycopg2-binary
pip install django-on-heroku

Why?

psycopg2 requires the Postgres utility file, named pg_config. The pg_config utility prints configuration parameters of the currently installed version of PostgreSQL. If it is missing since you don’t like to install Postgres locally, the solution is using psycopg2-binary. The django-heroku module requires psycopg2 and has been archived and no maintenance is available for it. A forked, django-on-heroku, has been created which uses psycopg2-binary.

Leave a comment