Thread: segfault on psycopg2 on CentOS
I am using Python2.7.8 and have a segfault in trying to import psycopg2.
This is to get Django working with PostgreSQL.
I was able to get a backtrace with gdb and here is what it is showing.
gdb python2.7
GNU gdb (GDB) CentOS (7.0.1-45.el5.centos) Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python2.7...done.
(gdb) run -c 'import psycopg2; print psycopg2'
Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2'
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x0029e844 in init_psycopg () at psycopg/psycopgmodule.c:814
814 Py_TYPE(&lobjectType) = &PyType_Type;
(gdb) bt
0 0x0029e844 in init_psycopg () at psycopg/psycopgmodule.c:814
1 0x001fee58 in _PyImport_LoadDynamicModule (name=0x8067790 "psycopg2._psycopg",
pathname=0x80c7ad0
"/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so",
fp=0x807c668)
at ./Python/importdl.c:53
2 0x001fcb7e in load_module (name=0x8067790 "psycopg2._psycopg", fp=0x2b9220,
pathname=0x80c7ad0
"/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", type=3,
loader=0xb7cfab6c)
at Python/import.c:1915
3 0x001fcdf5 in import_submodule (mod=0xb7f69854, subname=0x8067799 "_psycopg", fullname=0x8067790 "psycopg2._psycopg")
at Python/import.c:2700
4 0x001fd25c in load_next (mod=0xb7f69854, altmod=0xb7f69854, p_name=<value optimized out>, buf=0x8067790 "psycopg2._psycopg",
p_buflen=0xbfffdd74) at Python/import.c:2515
5 0x001fd59e in import_module_level (name=0xb7cf4bec "psycopg2._psycopg", globals=0xb7cf0604, locals=0xb7cf0604,
fromlist=0xb7f7005c, level=-1) at Python/import.c:2232
6 PyImport_ImportModuleLevel (name=0xb7cf4bec "psycopg2._psycopg", globals=0xb7cf0604, locals=0xb7cf0604, fromlist=0xb7f7005c,
level=-1) at Python/import.c:2288
7 0x001dd494 in builtin___import__ (self=0x0, args=0xb7cf4c5c, kwds=0x0) at Python/bltinmodule.c:49
8 0x0018103d in PyCFunction_Call (func=0xb7fce7ac, arg=0xb7cf4c5c,
kw=0x2b9220) at Objects/methodobject.c:85
9 0x0013a4ec in PyObject_Call (func=0xb7fce7ac, arg=0xb7cf4c5c, kw=0x0) at
Objects/abstract.c:2529
10 0x001ddb94 in PyEval_CallObjectWithKeywords (func=0xb7fce7ac, arg=0xb7cf4c5c, kw=0x0) at Python/ceval.c:3902
11 0x001e132c in PyEval_EvalFrameEx (f=0xb7f5847c, throwflag=0) at
Python/ceval.c:2346
12 0x001e6ad2 in PyEval_EvalCodeEx (co=0xb7f4dd10, globals=0xb7cf0604, locals=0xb7cf0604, args=0x0, argcount=0, kws=0x0,
kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3265
13 0x001e6b83 in PyEval_EvalCode (co=0xb7f4dd10, globals=0xb7cf0604,
locals=0xb7cf0604) at Python/ceval.c:673
14 0x001f9e5d in PyImport_ExecCodeModuleEx (name=0x80c2940 "psycopg2", co=0xb7f4dd10,
pathname=0x8066788
"/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc") at
Python/import.c:709
15 0x001fc612 in load_source_module (name=0x80c2940 "psycopg2",
pathname=0x8066788
"/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc",
fp=0x80cb4b8)
at Python/import.c:1099
16 0x001fe1f8 in load_package (name=0x80c2940 "psycopg2", pathname=<value optimized out>) at Python/import.c:1166
17 0x001fcdf5 in import_submodule (mod=0x26fee0, subname=0x80c2940 "psycopg2", fullname=0x80c2940 "psycopg2")
at Python/import.c:2700
18 0x001fd25c in load_next (mod=0x26fee0, altmod=0x26fee0, p_name=<value optimized out>, buf=0x80c2940 "psycopg2",
p_buflen=0xbfffe354) at Python/import.c:2515
19 0x001fd56a in import_module_level (name=0xb7cf5c74 "psycopg2", globals=0xb7fe2714, locals=0xb7fe2714, fromlist=0x26fee0,
level=-1) at Python/import.c:2224
20 PyImport_ImportModuleLevel (name=0xb7cf5c74 "psycopg2", globals=0xb7fe2714, locals=0xb7fe2714, fromlist=0x26fee0, level=-1)
at Python/import.c:2288
21 0x001dd494 in builtin___import__ (self=0x0, args=0xb7f3f914, kwds=0x0) at Python/bltinmodule.c:49
22 0x0018103d in PyCFunction_Call (func=0xb7fce7ac, arg=0xb7f3f914,
kw=0x2b9220) at Objects/methodobject.c:85
23 0x0013a4ec in PyObject_Call (func=0xb7fce7ac, arg=0xb7f3f914, kw=0x0) at
Objects/abstract.c:2529
24 0x001ddb94 in PyEval_CallObjectWithKeywords (func=0xb7fce7ac, arg=0xb7f3f914, kw=0x0) at Python/ceval.c:3902
25 0x001e132c in PyEval_EvalFrameEx (f=0xb7f78bfc, throwflag=0) at
Python/ceval.c:2346
26 0x001e6ad2 in PyEval_EvalCodeEx (co=0xb7f4d650, globals=0xb7fe2714, locals=0xb7fe2714, args=0x0, argcount=0, kws=0x0,
kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3265
27 0x001e6b83 in PyEval_EvalCode (co=0xb7f4d650, globals=0xb7fe2714,
locals=0xb7fe2714) at Python/ceval.c:673
28 0x00207b2a in run_mod (str=0x804a008 "import psycopg2; print psycopg2\n", start=257, globals=0xb7fe2714, locals=0xb7fe2714,
flags=0xbfffe838) at Python/pythonrun.c:1377
29 PyRun_StringFlags (str=0x804a008 "import psycopg2; print psycopg2\n", start=257, globals=0xb7fe2714, locals=0xb7fe2714,
flags=0xbfffe838) at Python/pythonrun.c:1340 ---Type <return> to continue, or q <return> to quit---
30 0x00208ea3 in PyRun_SimpleStringFlags (command=0x804a008 "import psycopg2; print psycopg2\n", flags=0xbfffe838)
at Python/pythonrun.c:981
31 0x0021d2e7 in Py_Main (argc=1, argv=0xbfffe904) at Modules/main.c:584
32 0x080485b2 in main (argc=1, argv=0x275ce0) at ./Modules/python.c:23
(gdb)
(Sorry if this backtrace is confusing; I had to remove the '#'s before all of the backtrace lines to get the post to be accepted as not 'top-posting')
Please help me with pointers on how to fix this.
On 03/11/2015 07:00 AM, Ed Davison wrote: > I am using Python2.7.8 and have a segfault in trying to import psycopg2. > > This is to get Django working with PostgreSQL. > > I was able to get a backtrace with gdb and here is what it is showing. Might also help to provide some context about what you where doing when the segfault happened. Where are you importing psycopg2 into, or is this something Django is doing? Doing what sort of operation, if any? > -- Adrian Klaver adrian.klaver@aklaver.com
On Wed, Mar 11, 2015 at 2:00 PM, Ed Davison <EDavison@getmns.com> wrote: > Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2' ... > "/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", I think you have some python path confusion and you are mixing up two python environments compiled with different parameters. Try running /opt/python2.7.8/bin/python instead. -- Daniele
On 03/11/2015 07:00 AM, Ed Davison wrote: >> I am using Python2.7.8 and have a segfault in trying to import psycopg2. >> >> This is to get Django working with PostgreSQL. >> >> I was able to get a backtrace with gdb and here is what it is showing. >Might also help to provide some context about what you where doing when the segfault happened. >Where are you importing psycopg2 into, or is this something Django is doing? >Doing what sort of operation, if any? When I load my project to do any work on it with Django I get a segfault. When I run the Django manage.py as "python2.7-vv manage.py" I get the following: # trying /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); Segmentation fault I have tested this with python2.7 to just simply load the psycopg2 library with the import statement and just loading thelibrary causes a segfault as earlier stated in my backtrace. Ed
On 03/11/2015 07:21 AM, Ed Davison wrote: > On 03/11/2015 07:00 AM, Ed Davison wrote: >>> I am using Python2.7.8 and have a segfault in trying to import psycopg2. >>> >>> This is to get Django working with PostgreSQL. >>> >>> I was able to get a backtrace with gdb and here is what it is showing. > >> Might also help to provide some context about what you where doing when the segfault happened. > >> Where are you importing psycopg2 into, or is this something Django is doing? > >> Doing what sort of operation, if any? > > When I load my project to do any work on it with Django I get a segfault. When I run the Django manage.py as "python2.7-vv manage.py" I get the following: > > # trying /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so > dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); > Segmentation fault > > I have tested this with python2.7 to just simply load the psycopg2 library with the import statement and just loading thelibrary causes a segfault as earlier stated in my backtrace. To follow up on Danieles comment: 1) Are you running in a virtualenv? 2) Do you have more than one installation of Python? 3) More to the point what does python2.7 point to? > > Ed > > > -- Adrian Klaver adrian.klaver@aklaver.com
On 03/11/2015 07:21 AM, Ed Davison wrote: > On 03/11/2015 07:00 AM, Ed Davison wrote: >>> I am using Python2.7.8 and have a segfault in trying to import psycopg2. >>> >>> This is to get Django working with PostgreSQL. >>> >>> I was able to get a backtrace with gdb and here is what it is showing. > >> Might also help to provide some context about what you where doing when the segfault happened. > >> Where are you importing psycopg2 into, or is this something Django is doing? > >> Doing what sort of operation, if any? > > When I load my project to do any work on it with Django I get a segfault. When I run the Django manage.py as "python2.7-vv manage.py" I get the following: > > # trying > /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so > dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg > .so", 2); Segmentation fault > > I have tested this with python2.7 to just simply load the psycopg2 library with the import statement and just loading thelibrary causes a segfault as earlier stated in my backtrace. To follow up on Danieles comment: 1) Are you running in a virtualenv? No, I am not. 2) Do you have more than one installation of Python? Yes, I have python 2.7.8 and python 2.4.3. Running on CentOS 5.9 there is no package for upgrading the main and only versionto anything newer. 3) More to the point what does python2.7 point to? # ls -al /usr/bin/python2.7 lrwxrwxrwx 1 root root 30 Nov 10 15:55 /usr/bin/python2.7 -> /opt/python2.7.8/bin/python2.7
On Wed, Mar 11, 2015 at 2:00 PM, Ed Davison <EDavison@getmns.com> wrote: > Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2' ... > "/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", I think you have some python path confusion and you are mixing up two python environments compiled with different parameters.Try running /opt/python2.7.8/bin/python instead. -- Results: > /opt/python2.7.8/bin/python manage.py Segmentation fault > Results from "/opt/python2.7.8/bin/python -v manage.py " : ... import psycopg2 # directory /opt/python2.7.8/lib/python2.7/site-packages/psycopg2 # /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc matches /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.py import psycopg2 # precompiled from /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); Segmentation fault
On Wed, Mar 11, 2015 at 2:47 PM, Ed Davison <EDavison@getmns.com> wrote: >> # trying >> /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so >> dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg >> .so", 2); Segmentation fault >> >> I have tested this with python2.7 to just simply load the psycopg2 library with the import statement and just loadingthe library causes a segfault as earlier stated in my backtrace. > > To follow up on Danieles comment: > > 1) Are you running in a virtualenv? > No, I am not. > > 2) Do you have more than one installation of Python? > Yes, I have python 2.7.8 and python 2.4.3. Running on CentOS 5.9 there is no package for upgrading the main and only versionto anything newer. > > 3) More to the point what does python2.7 point to? > # ls -al /usr/bin/python2.7 > lrwxrwxrwx 1 root root 30 Nov 10 15:55 /usr/bin/python2.7 -> /opt/python2.7.8/bin/python2.7 This is a bit messed up. Either your Python environment is inconsistent or it is WRT when psycopg was compiled. If you wanted to investigate further maybe an "ldd /path/to/_psycopg.so" would suggest you something. What you may try to do is to create a virtualenv and pip install psycopg2 into it, which would compile a fresh copy. -- Daniele
On 03/11/2015 07:51 AM, Ed Davison wrote: > On Wed, Mar 11, 2015 at 2:00 PM, Ed Davison <EDavison@getmns.com> wrote: > > >> Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2' > > ... > >> "/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", > > I think you have some python path confusion and you are mixing up two python environments compiled with different parameters.Try running /opt/python2.7.8/bin/python instead. > > -- > > Results: >> /opt/python2.7.8/bin/python manage.py > Segmentation fault >> > > Results from "/opt/python2.7.8/bin/python -v manage.py " : > ... > import psycopg2 # directory /opt/python2.7.8/lib/python2.7/site-packages/psycopg2 > # /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc matches /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.py > import psycopg2 # precompiled from /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc > dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); > Segmentation fault > > Hmm, so how did you install psycopg2? From source or a package? -- Adrian Klaver adrian.klaver@aklaver.com
On 03/11/2015 07:51 AM, Ed Davison wrote: > On Wed, Mar 11, 2015 at 2:00 PM, Ed Davison <EDavison@getmns.com> wrote: > > >> Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2' > > ... > >> "/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", > > I think you have some python path confusion and you are mixing up two python environments compiled with different parameters.Try running /opt/python2.7.8/bin/python instead. > > -- > > Results: >> /opt/python2.7.8/bin/python manage.py > Segmentation fault >> > > Results from "/opt/python2.7.8/bin/python -v manage.py " : > ... > import psycopg2 # directory /opt/python2.7.8/lib/python2.7/site-packages/psycopg2 > # /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc matches /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.py > import psycopg2 # precompiled from /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc > dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); > Segmentation fault > > Hmm, so how did you install psycopg2? From source or a package? I installed form source since CentOS only has psycopg2 for python 2.4.3 and I need python 2.7 for Django. So, I did a "python2.7setup.py install" to get it installed into the python2.7 tree. Ed
On 03/11/2015 04:45 PM, Ed Davison wrote: > On 03/11/2015 07:51 AM, Ed Davison wrote: >> On Wed, Mar 11, 2015 at 2:00 PM, Ed Davison <EDavison@getmns.com> wrote: >> >> >>> Starting program: /usr/bin/python2.7 -c 'import psycopg2; print psycopg2' >> >> ... >> >>> "/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", >> >> I think you have some python path confusion and you are mixing up two python environments compiled with different parameters.Try running /opt/python2.7.8/bin/python instead. >> >> -- >> >> Results: >>> /opt/python2.7.8/bin/python manage.py >> Segmentation fault >>> >> >> Results from "/opt/python2.7.8/bin/python -v manage.py " : >> ... >> import psycopg2 # directory /opt/python2.7.8/lib/python2.7/site-packages/psycopg2 >> # /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc matches /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.py >> import psycopg2 # precompiled from /opt/python2.7.8/lib/python2.7/site-packages/psycopg2/__init__.pyc >> dlopen("/opt/python2.7.8/lib/python2.7/site-packages/psycopg2/_psycopg.so", 2); >> Segmentation fault >> >> > > Hmm, so how did you install psycopg2? > From source or a package? > > I installed form source since CentOS only has psycopg2 for python 2.4.3 and I need python 2.7 for Django. So, I did a"python2.7 setup.py install" to get it installed into the python2.7 tree. Well that seems OK on the face of it. I would do as Daniele suggested: 1) ldd /path/to/_psycopg.so 2) Create a virtualenv and do a build inside of it. In addition I have a suggestion. In the directory that you built psycopg2 in do: python setup.py clean --all then python setup.py build There will a bunch of copy commands then the gcc commands. Copy and paste the gcc output here, so we can see what it is building against. My suspicion is that you are inadvertently cross compiling against some Python 2.4.3 libraries. > > Ed > -- Adrian Klaver adrian.klaver@aklaver.com