dackdive's blog

新米webエンジニアによる技術ブログ。JavaScript(React), Salesforce, Python など

[Heroku][Django]Postgres.appで `'django_postgrespool' isn't an available database backend.` エラー

メモ。
Django アプリケーションをローカルで実行したらこんなエラーが出た。
(確認した PC は Mac OS X Yosemite v10.10.5)

(venv)$ heroku local web
forego | starting web.1 on port 5000
web.1  | [2015-12-13 12:57:53 +0900] [2925] [INFO] Starting gunicorn 19.3.0
web.1  | [2015-12-13 12:57:53 +0900] [2925] [INFO] Listening at: http://0.0.0.0:5000 (2925)
web.1  | [2015-12-13 12:57:53 +0900] [2925] [INFO] Using worker: sync
web.1  | [2015-12-13 12:57:53 +0900] [2928] [INFO] Booting worker with pid: 2928
web.1  | [2015-12-13 12:57:54 +0900] [2928] [ERROR] Exception in worker process:
web.1  | eroku/python_getting_started/venv/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
web.1  | ad_wsgiapp()
web.1  | [2015-12-13 12:57:54 +0900] [2928] [INFO] Worker exiting (pid: 2928)
web.1  | [2015-12-13 12:57:54 +0900] [2925] [INFO] Shutting down: Master
web.1  | [2015-12-13 12:57:54 +0900] [2925] [INFO] Reason: Worker failed to boot.

これだけだとよくわからないのでただの Django アプリとして実行してみる。

(venv)$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/yamazaki/.pyenv/versions/2.7.10/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module>
    class Permission(models.Model):
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/django/db/utils.py", line 129, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_postgrespool' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: dlopen(/Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _lo_lseek64
  Referenced from: /Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Expected in: /usr/lib/libpq.5.dylib
 in /Users/yamazaki/workspace/heroku/python_getting_started/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so

んーなんか libpq.5.dylib とかいうファイルでエラーになってる。。。

調べてみて、結局こちらにある方法で解決した。

python - Problems using psycopg2 on Mac OS (Yosemite) - Stack Overflow

以下のコマンドを実行。

$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib

元々の /usr/lib/libpq.5.dylib が古いから Postgres.app に同梱されている方に置き換えるみたい。

Homebrew から Postgres 入れた時は発生しなかったはず。