1

I am trying to host a Django app on Heroku. The app works fine on my computer as long as I don't use django-heroku (because I can't install it), and it works fine on Heroku as long as it does have django-heroku. This is not a pressing issue, but it is sort of annoying to have to remove django-heroku to make edits on my computer, and then have to re-insert it before pushing to heroku.

The ideal solution would be to get django-heroku installed on my computer.

Specifications:

  • Mac running macOS
  • Conda environment, python 3.7 and 3.8

Here is what I have found so far:

  • pip 20.0.2 from /Users/lucas/opt/anaconda3/lib/python3.7/site-packages/pip (python 3.7):
    • Cannot install django-heroku (See error below)
  • pip 20.1.1 from /Users/lucas/Library/Python/3.7/lib/python/site-packages/pip (python 3.7):
    • Can install django-heroku, however:
    • Gives me this warning: (still installs without any problems)
      • WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

    • running the script with all pythons in the environment say no module called django_heroku

The first version of pip I specified that couldn't install django-heroku gives this error:

pip install django-heroku
Collecting django-heroku
  Using cached django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
Collecting psycopg2
  Using cached psycopg2-2.8.5.tar.gz (380 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/lucas/opt/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info
         cwd: /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info/psycopg2.egg-info
    writing /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file '/private/var/folders/r1/c30g6kr946l2czzpkr2mvrd80000gn/T/pip-install-q1m4s1hh/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'

    Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I'm not an expert on how things like this work, so I included as much information as I could. I appreciate any help you can give on this.

CircuitSacul
  • 1,594
  • 12
  • 32
  • What does your requirements.txt look like? Have you tried using the `psycopg2-binary` package instead of `psycopg2`? – Ben Jul 10 '20 at 22:47
  • Duplicate of https://stackoverflow.com/q/20170895/2650249 – hoefling Jul 11 '20 at 14:33
  • @hoefling it looks to me like that question is specific to PostgreSQL, which I am not using. I am using SQLite3 – CircuitSacul Jul 11 '20 at 23:26
  • It doesn't matter what database you use. What matters is that `psycopg2` is required by `django-heroku`, so you have to install PostgreSQL and put `pg_config` into path. – hoefling Jul 11 '20 at 23:52

1 Answers1

7

First, django-heroku is no longer maintained, so my advice is to not use it.

Your problem, though is with psycopg2, as the error mentions, not django-heroku directly. Since django-heroku depends on psycopg2, installing psycopg2-binary probably won't help - and there can be issues with this as well, it's not suitable for serving your site from, although you're probably not doing that on OS X.

To get it working, you need to install the PostgreSQL libraries:

brew install postgresql

Depending on a few things, you may also have problems after that. If you see any errors about gcc and ssl, you can try running:

setenv LDFLAGS "-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"

For fish, or if you running bash:

export LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"

It can be tricky, so that may not be enough.

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
  • You recommend not using django-heroku, what is the alternative? My website admin page doesn't work properly without out it. – CircuitSacul Jul 11 '20 at 20:41
  • It should work fine without it. I deploy to heroku without any libraries and it works well. What do you mean by doesn't work correctly? If it's static files (the pages are white with no styling), you can add whitenoise directly: http://whitenoise.evans.io/en/stable/index.html – Tom Carrick Jul 12 '20 at 09:27