user1460961
user1460961

Reputation: 1

Symbol not found: _PQbackendPID with Django project

Running on MAC os 10.6.8 with postgresSQL installed, as well django - using python2.7 Also installed psycopg2 and dj-database-url using pip in my virtual env And added these two lines to my setting.py:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

Based on instructions for Heroku in: https://devcenter.heroku.com/articles/django#database_settings When running:

python manage.py runserver

I am getting this error:

ImportError: dlopen(/Users.... venv/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Users.... venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: dynamic lookup

I kept searching for hours and tried all kind of thing including the advice on: Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID to no avail.

Wonder if anyone had such an issue and had any luck.

Upvotes: 0

Views: 1228

Answers (2)

Soroush Nejad
Soroush Nejad

Reputation: 423

I had the same problem as you guys and I had read many pages and I couldn't find the answer in any of them. Many solution was about installing from source file and don't relate to the virtual environment. I've found and tested following solution and it solve my problem.

1- Make sure your Postgres is NOT higher than 9.4 version according to psycopg2. Check python version as well. I use Postgres 3.9.9.

2- The problem is behind different version of Python(32/64 bit). It should comply with your operation system's bit architecture which is 64bit. Uninstall all versions of Python and pip from your system. Instruction you can find here but do NOT remove Python2.7 which is Apple-supplied system Python.

3- Install "Mac OS X 64-bit/32-bit" installer from python official website and install it. After that install pip. Note that you should use the command "python3.5" for using Python version 3.5. You might install virtualenv from the new pip as well.

4- After all that you can go on your virtualenv and type "pip3 install -r requirement.txt" for installing all dependencies on your local machine.

Hope this can help you.

Upvotes: 1

RichLitt
RichLitt

Reputation: 482

I had the same problem. Instead of installing the dependencies as Heroku suggests using

pip install Django psycopg2 dj-database-url

clone whatever repo you're hoping to run in venv, keeping its original settings.py. Then:

source venv/bin/activate

to activate the new environment, cd into your new repo, and python manage.py runserver. Should be set.

Alternatively, you could remake PostGreSQL, and run again, but that's a bit more of a task - it would work for psycopg2, though. As far as I can tell that issue comes from using an 64 or i386 build when you should be using a 32 build - but I'm not sure about this, and the above solution works well to solve the problem and use venv for what you're actually going to be using it for, most likely.

Upvotes: 2

Related Questions