Обсуждение: Trouble installing psycopg2 on Mac OSX 10.6
Hi,
I had psycopg2-2.0.8 running with Postgres 8.3.6 on my old MacBook. However, when I upgraded to a new MacBook, it didn’t migrate properly and was giving an error that indicated that the postgres libraries were built for the wrong architecture. I think this might be a 64-bit issue, but unfortunately I lost the exact error message.
In any event, I tried a complete new installation, upgrading to Postgres 8.4.8 and psycopg2-2.4.1. First I tried the easy_install version of psycopg2 and it made an egg but again complained about the libpq.dylib. The installation seemed to be picking up the libraries from the old Postgres (8.3.6) instead of the new one. [terminal output below]. So I downloaded psycopg2-2.4.1 from source and tried to build and install. I edited the setup.cfg to point at the new Postgres installation (or so I thought). An aside here— I used the “one click” .dmg file to install Postgres 8.4.8 and it installed it in /Library/PostgreSQL/8.4 instead of the usual /usr/local/ directory. The psycopg2 install failed because it couldn’t find the pg_config file. Yet when I go and look where I pointed in the setup.cfg file, there it is. So, I’m totally confused now.
Any help would be appreciated,
Bill Carithers
Here’s the install terminal session:
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ emacs setup.cfg
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ python setup.py install
running install
running build
running build_py
running build_ext
Error: Unable to find 'pg_config' file in '/Library/PostgreSQL/8.4/bin'
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ cd /Library/PostgreSQL/8.4/bin
c4-2c-3-1-f0-3a:bin williamcarithers$ ls
clusterdb dropuser pg_ctl pgbench psql
createdb ecpg pg_dump pltcl_delmod reindexdb
createlang initdb pg_dumpall pltcl_listmod vacuumdb
createuser oid2name pg_resetxlog pltcl_loadmod vacuumlo
dropdb pg_config pg_restore postgres
droplang pg_controldata pg_standby postmaster
Here’s the terminal ouput for the easy_install try:
c4-2c-3-1-f0-3a:~ williamcarithers$ easy_install-2.6 psycopg2
Searching for psycopg2
Reading http://pypi.python.org/simple/psycopg2/
Reading http://initd.org/projects/psycopg2
Best match: psycopg2 2.4.1
Downloading http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.1.tar.gz
Processing psycopg2-2.4.1.tar.gz
Running psycopg2-2.4.1/setup.py -q bdist_egg --dist-dir /var/folders/3s/3s7l-F7gHiqL+Sl620nUhE+++TU/-Tmp-/easy_install-4RDtVl/psycopg2-2.4.1/egg-dist-tmp-RcyPTj
no previously-included directories found matching 'doc/src/_build'
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
ld: warning: in /usr/local/pgsql/lib/libpq.dylib, file was built for i386 which is not the architecture being linked (ppc)
ld: warning: in /usr/local/pgsql/lib/libpq.dylib, file was built for i386 which is not the architecture being linked (x86_64)
zip_safe flag not set; analyzing archive contents...
psycopg2.tests.types_basic: module references __file__
Adding psycopg2 2.4.1 to easy-install.pth file
Installed /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg
Processing dependencies for psycopg2
Finished processing dependencies for psycopg2
Exception TypeError: TypeError("'NoneType' object is not callable",) in <bound method Popen.__del__ of <subprocess.Popen object at 0x100787250>> ignored
c4-2c-3-1-f0-3a:~ williamcarithers$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/__init__.py", line 71, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so
>>>
I had psycopg2-2.0.8 running with Postgres 8.3.6 on my old MacBook. However, when I upgraded to a new MacBook, it didn’t migrate properly and was giving an error that indicated that the postgres libraries were built for the wrong architecture. I think this might be a 64-bit issue, but unfortunately I lost the exact error message.
In any event, I tried a complete new installation, upgrading to Postgres 8.4.8 and psycopg2-2.4.1. First I tried the easy_install version of psycopg2 and it made an egg but again complained about the libpq.dylib. The installation seemed to be picking up the libraries from the old Postgres (8.3.6) instead of the new one. [terminal output below]. So I downloaded psycopg2-2.4.1 from source and tried to build and install. I edited the setup.cfg to point at the new Postgres installation (or so I thought). An aside here— I used the “one click” .dmg file to install Postgres 8.4.8 and it installed it in /Library/PostgreSQL/8.4 instead of the usual /usr/local/ directory. The psycopg2 install failed because it couldn’t find the pg_config file. Yet when I go and look where I pointed in the setup.cfg file, there it is. So, I’m totally confused now.
Any help would be appreciated,
Bill Carithers
Here’s the install terminal session:
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ emacs setup.cfg
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ python setup.py install
running install
running build
running build_py
running build_ext
Error: Unable to find 'pg_config' file in '/Library/PostgreSQL/8.4/bin'
c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ cd /Library/PostgreSQL/8.4/bin
c4-2c-3-1-f0-3a:bin williamcarithers$ ls
clusterdb dropuser pg_ctl pgbench psql
createdb ecpg pg_dump pltcl_delmod reindexdb
createlang initdb pg_dumpall pltcl_listmod vacuumdb
createuser oid2name pg_resetxlog pltcl_loadmod vacuumlo
dropdb pg_config pg_restore postgres
droplang pg_controldata pg_standby postmaster
Here’s the terminal ouput for the easy_install try:
c4-2c-3-1-f0-3a:~ williamcarithers$ easy_install-2.6 psycopg2
Searching for psycopg2
Reading http://pypi.python.org/simple/psycopg2/
Reading http://initd.org/projects/psycopg2
Best match: psycopg2 2.4.1
Downloading http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.1.tar.gz
Processing psycopg2-2.4.1.tar.gz
Running psycopg2-2.4.1/setup.py -q bdist_egg --dist-dir /var/folders/3s/3s7l-F7gHiqL+Sl620nUhE+++TU/-Tmp-/easy_install-4RDtVl/psycopg2-2.4.1/egg-dist-tmp-RcyPTj
no previously-included directories found matching 'doc/src/_build'
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
./psycopg/config.h:71: warning: ‘Dprintf’ defined but not used
ld: warning: in /usr/local/pgsql/lib/libpq.dylib, file was built for i386 which is not the architecture being linked (ppc)
ld: warning: in /usr/local/pgsql/lib/libpq.dylib, file was built for i386 which is not the architecture being linked (x86_64)
zip_safe flag not set; analyzing archive contents...
psycopg2.tests.types_basic: module references __file__
Adding psycopg2 2.4.1 to easy-install.pth file
Installed /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg
Processing dependencies for psycopg2
Finished processing dependencies for psycopg2
Exception TypeError: TypeError("'NoneType' object is not callable",) in <bound method Popen.__del__ of <subprocess.Popen object at 0x100787250>> ignored
c4-2c-3-1-f0-3a:~ williamcarithers$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/__init__.py", line 71, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/psycopg2-2.4.1-py2.6-macosx-10.6-universal.egg/psycopg2/_psycopg.so
>>>
Hello Bill, On Mon, May 16, 2011 at 8:05 PM, Bill Carithers <wccarithers@lbl.gov> wrote: > The psycopg2 install failed because it couldn’t find the > pg_config file. Yet when I go and look where I pointed in the setup.cfg > file, there it is. So, I’m totally confused now. This is curious. The procedure to find the pg_config in the setup.py is honestly messy, but it shouldn't fail so badly. Could you please check with some print or some breakpoint: a) if you specify a pg_config in the setup.cfg or in the command line, you should find it as "self.pg_config" in finalize_options() (line 248 of setup.py). If nothing is specified, self.pg_config should be None and should be obtained by autodetect_pg_config_path(). b) the try case in get_pg_config (line 88) is probably too broad. Can you try to remove it and see if Popen fails with an exception which is incorrectly interpreted as pg_config not found? Thank you very much. -- Daniele
Hi Daniele, Thanks for the prompt reply. I tried the two things you suggested. Results are: c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ python setup.py install running install running build running build_py running build_ext pg_config is set to /Library/PostgreSQL/8.4/bin <-- the print statement error: Permission denied <-- removing the try/except So it looks like it is getting the correct pg_config from the setup.cfg file. Stupid question--it is looking for the executable pg_config in ./bin and not the pg_config.h in the ./include directory, right? Thanks, Bill On 5/16/11 1:09 PM, "Daniele Varrazzo" <daniele.varrazzo@gmail.com> wrote: > Hello Bill, > > On Mon, May 16, 2011 at 8:05 PM, Bill Carithers <wccarithers@lbl.gov> wrote: > >> The psycopg2 install failed because it couldn¹t find the >> pg_config file. Yet when I go and look where I pointed in the setup.cfg >> file, there it is. So, I¹m totally confused now. > > This is curious. The procedure to find the pg_config in the setup.py > is honestly messy, but it shouldn't fail so badly. > > Could you please check with some print or some breakpoint: > > a) if you specify a pg_config in the setup.cfg or in the command line, > you should find it as "self.pg_config" in finalize_options() (line 248 > of setup.py). If nothing is specified, self.pg_config should be None > and should be obtained by autodetect_pg_config_path(). > > b) the try case in get_pg_config (line 88) is probably too broad. Can > you try to remove it and see if Popen fails with an exception which is > incorrectly interpreted as pg_config not found? > > Thank you very much. > > -- Daniele
On Mon, May 16, 2011 at 9:46 PM, Bill Carithers <wccarithers@lbl.gov> wrote: > Hi Daniele, > > Thanks for the prompt reply. I tried the two things you suggested. Results > are: > > c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ python setup.py install > running install > running build > running build_py > running build_ext > pg_config is set to /Library/PostgreSQL/8.4/bin <-- the print statement the setup value should be the full path, not the containing directory, something like /Library/PostgreSQL/8.4/bin/pg_config I guess. > error: Permission denied <-- removing the try/except Seems compatible with trying to execute a directory. > So it looks like it is getting the correct pg_config from the setup.cfg > file. Stupid question--it is looking for the executable pg_config in ./bin > and not the pg_config.h in the ./include directory, right? If you set a value into setup.cfg, it shouldn't be searching for anything, but just use that value, and fail if it doesn't work as an executable. -- Daniele
Hi Daniele, OK, progress. Now it seems to find all the stuff in the new Postgres installation, and the build/install seems to work-- makes an egg in site-packages and so on. However, when I try to import psycopg2, I get an error: Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Python/2.6/site-packages/psycopg2/__init__.py", line 71, in <module> from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg.so Expected in: flat namespace in /Library/Python/2.6/site-packages/psycopg2/_psycopg.so I'm not including all the build output (it's very long) unless you think it would be helpful. Thanks, Bill On 5/16/11 3:09 PM, "Daniele Varrazzo" <daniele.varrazzo@gmail.com> wrote: > On Mon, May 16, 2011 at 9:46 PM, Bill Carithers <wccarithers@lbl.gov> wrote: >> Hi Daniele, >> >> Thanks for the prompt reply. I tried the two things you suggested. Results >> are: >> >> c4-2c-3-1-f0-3a:psycopg2-2.4.1 williamcarithers$ python setup.py install >> running install >> running build >> running build_py >> running build_ext >> pg_config is set to /Library/PostgreSQL/8.4/bin <-- the print statement > > the setup value should be the full path, not the containing directory, > something like > > /Library/PostgreSQL/8.4/bin/pg_config > > I guess. > >> error: Permission denied <-- removing the try/except > > Seems compatible with trying to execute a directory. > >> So it looks like it is getting the correct pg_config from the setup.cfg >> file. Stupid question--it is looking for the executable pg_config in ./bin >> and not the pg_config.h in the ./include directory, right? > > If you set a value into setup.cfg, it shouldn't be searching for > anything, but just use that value, and fail if it doesn't work as an > executable. > > -- Daniele
On May 16, 2011, at 6:42 PM, Bill Carithers wrote: > Hi Daniele, > > OK, progress. Now it seems to find all the stuff in the new Postgres > installation, and the build/install seems to work-- makes an egg in > site-packages and so on. However, when I try to import psycopg2, I get an > error: > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import psycopg2 > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/Library/Python/2.6/site-packages/psycopg2/__init__.py", line 71, in > <module> > from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID > ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2/_psycopg.so, > 2): Symbol not found: _PQbackendPID > Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg.so > Expected in: flat namespace > in /Library/Python/2.6/site-packages/psycopg2/_psycopg.so > > I'm not including all the build output (it's very long) unless you think it > would be helpful. Be sure to nuke any old psycopgs egg files you might have hanging around in your python path. Cheers, M
On Mon, May 16, 2011 at 11:42 PM, Bill Carithers <wccarithers@lbl.gov> wrote: > OK, progress. Good :) > Now it seems to find all the stuff in the new Postgres > installation, and the build/install seems to work-- makes an egg in > site-packages and so on. However, when I try to import psycopg2, I get an > error: > [...] > 2): Symbol not found: _PQbackendPID At this point we are going into OS X realm, about which I know little. However this error has been reported many times. Take a look at this article for instance: <http://blog.timc3.com/2010/08/20/psycopg2-os-x-_pqbackendpid/> -- Daniele