heliotrope
heliotrope

Reputation: 349

psycopg2 can't find symbol _PQbackendPID

Trying to get started with django, and for some reason psycopg2 isn't locating my postgres instance. Here's the error message:

(env)Ryans-MacBook-Pro:crib_db nonzero$ python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x36f1584>
Traceback (most recent call last):
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 20, in <module>
import psycopg2 as Database  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/psycopg2/__init__.py", line 50, in <module>
  from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
  Referenced from: /Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/psycopg2/_psycopg.so
  Expected in: dynamic lookup


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
autoreload.raise_last_exception()
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
six.reraise(*_exception)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
  File "/Users/nonzero/Programming/Data_Wizard/env/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
...
...
...

I've made sure I can access my database using psql on the commandline, and using ps -e | grep postgres I get:

1647 ??         0:00.31 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
1649 ??         0:00.01 postgres: checkpointer process       
1650 ??         0:00.30 postgres: writer process       
1651 ??         0:00.26 postgres: wal writer process       
1652 ??         0:00.24 postgres: autovacuum launcher process       
1653 ??         0:00.72 postgres: stats collector process 
75317 ttys001    0:00.00 grep postgres

I also suspect it may be some versioning issue, but I'm using current versions of both psycopg2(2.6.1) and postgres(9.4.5).

I'm also getting the error just trying to write simple queries in some code using sqlalchemy, so I don't think its django-specific.

Upvotes: 1

Views: 560

Answers (1)

heliotrope
heliotrope

Reputation: 349

For anyone else with similar problems, I solved this by removing all versions of python and postgres with brew rmtree. I also had to remove an earlier install of python that ended up in /Library/Frameworks directory, cleared redundancies out of my PATH in .bash-profile and fresh brew install on everything afterwards. Also, brew doctor to resolve any symlink issues. Not 100% what exactly resolved it, however.

Upvotes: 1

Related Questions