Unable to import libxml2mod from the python script

514 views
Skip to first unread message

Superman

unread,
Jun 2, 2010, 9:57:27 AM6/2/10
to Django users
I have a django site that is integrated with scrapy, but when the
scrapy code is called from the view, I get this error:

File "/usr/local/lib/python2.5/site-packages/libxml2.py", line 1, in
<module>
import libxml2mod

ImportError: /usr/local/lib/python2.5/site-packages/
libxml2mod.so:
undefined symbol:xmlTextReaderSetup

But using the same python executable file on shell, I can import
libxml2 and libxml2mod fine!

>>> import libxml2mod
>>> import libxml2
>>>

Does anyone have an idea why my program is not working from .py file
as import is working perfect from python prompt.

Darren

unread,
Jun 2, 2010, 1:32:55 PM6/2/10
to django...@googlegroups.com
Just grasping at straws here, but could it have anything to do with
permissions or the python path? I don't fully understand how imports
work. But, those are things I'd explore first.

Darren

> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en
> .
>

Jeliuc Alexandr

unread,
Jun 2, 2010, 2:14:00 PM6/2/10
to Django users
You should check env path variables diff between shell and code
execution. Another way check this error path is there libxml2 or not.
it may be in usr/lib/python2.5. or something like that.

Superman

unread,
Jun 2, 2010, 10:38:13 PM6/2/10
to Django users
Thanks for your reply. How do you check env path variables diff
between shell and code
execution?

To my wsgi file, I have this line "#!/usr/local/bin/python" which
tells which interpreter to use. And yes, libxml2.py and libxml2mod.so
files are there in "/usr/local/lib/python2.5/site-packages/" folder.
Also running ldd on libxml2mod.so outputs:

libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x00002b5368ebe000)

Also my python path looks correct. The django shell manages to find
and import the respective modules.

I have a feeling that the solution is quite easy after which I will
hit myself in the head hard! I have been pulling hair over this
problem since days now. Anyone, with any suggestions/info on how they
got their libxml2 module to work, please don't hesitate to reply.

Thanks

Bruce Wang

unread,
Jun 2, 2010, 11:20:39 PM6/2/10
to django...@googlegroups.com
On Thu, Jun 3, 2010 at 12:38 PM, Superman <ramsey...@gmail.com> wrote:
Thanks for your reply. How do you check env path variables diff
between shell and code
execution?

To my wsgi file, I have this line "#!/usr/local/bin/python" which
tells which interpreter to use. And yes, libxml2.py and libxml2mod.so
files are there in "/usr/local/lib/python2.5/site-packages/" folder.
Also running ldd on libxml2mod.so outputs:

libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x00002b5368ebe000)
 
Are you running your django app under mod_wsgi? It may not running with your interpreter in your #! line.

Try using
import sys; print sys.executable
in your wsgi file to find out the exact interpreter your wsgi server is using.

BTW: I would suggest you to look at lxml[1] which is another libxml2/libxslt binding but more elegant and pythonic.

[1] http://codespeak.net/lxml/

--
simple is good
http://brucewang.net
http://twitter.com/number5

Graham Dumpleton

unread,
Jun 2, 2010, 11:23:50 PM6/2/10
to Django users


On Jun 3, 12:38 pm, Superman <ramseydsi...@gmail.com> wrote:
> Thanks for your reply. How do you check env path variables diff
> between shell and code
> execution?
>
> To my wsgi file, I have this line "#!/usr/local/bin/python" which
> tells which interpreter to use.

Generally, no it doesn't. If this is a WSGI script file used by
mod_wsgi or uWSGI that line has absolutely no meaning.

The Python interpreter that mod_wsgi or uWSGI was specifically
compiled against will be used.

State clearly what hosting mechanism and web server you are using and
how you installed them, ie., from source code or binary packages. Also
indicate how you have configured them for your WSGI script and what
your WSGI script file contains.

You are making people guess too much as to how you have things set up.

Graham

Graham Dumpleton

unread,
Jun 2, 2010, 11:26:18 PM6/2/10
to Django users


On Jun 3, 1:20 pm, Bruce Wang <br...@brucewang.net> wrote:
> On Thu, Jun 3, 2010 at 12:38 PM, Superman <ramseydsi...@gmail.com> wrote:
> > Thanks for your reply. How do you check env path variables diff
> > between shell and code
> > execution?
>
> > To my wsgi file, I have this line "#!/usr/local/bin/python" which
> > tells which interpreter to use. And yes, libxml2.py and libxml2mod.so
> > files are there in "/usr/local/lib/python2.5/site-packages/" folder.
> > Also running ldd on libxml2mod.so outputs:
>
> > libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x00002b5368ebe000)
>
> Are you running your django app under mod_wsgi? It may not running with your
> interpreter in your #! line.
>
> Try using
> import sys; print sys.executable
> in your wsgi file to find out the exact interpreter your wsgi server is
> using.

No it will not. Under mod_python and mod_wsgi that is usually going to
be 'httpd' executable.

More important value is 'sys.prefix', plus running 'ldd' on the .so
file for the Apache module.

Graham

Bruce Wang

unread,
Jun 2, 2010, 11:36:24 PM6/2/10
to django...@googlegroups.com


On Thu, Jun 3, 2010 at 1:26 PM, Graham Dumpleton <graham.d...@gmail.com> wrote:

>
> Are you running your django app under mod_wsgi? It may not running with your
> interpreter in your #! line.
>
> Try using
> import sys; print sys.executable
> in your wsgi file to find out the exact interpreter your wsgi server is
> using.

No it will not. Under mod_python and mod_wsgi that is usually going to
be 'httpd' executable.

More important value is 'sys.prefix', plus running 'ldd' on the .so
file for the Apache module.

Graham


Oops, sorry about giving out wrong instructions.

Darren

unread,
Jun 3, 2010, 8:06:19 AM6/3/10
to django...@googlegroups.com
Go to /usr/local/bin and do ls -l and see if python is a sym link. If
so, see where it points and verify it points to python25. Your modules
are here:
> /usr/local/lib/python2.5/site-packages

Verify that the python executable matches.

Darren

Jeliuc Alexandr

unread,
Jun 3, 2010, 8:22:36 AM6/3/10
to Django users
You can use ipython or simple idle to see it
/usr/local/lib/python2.5.
but
/bin/python

are you sure about default version?

On Jun 3, 3:06 pm, Darren <backdoc...@gmail.com> wrote:
> Go to  /usr/local/bin and do ls -l and see if python is a sym link. If  
> so, see where it points and verify it points to python25. Your modules  
> are here:
>
> > /usr/local/lib/python2.5/site-packages
>
> Verify that the python executable matches.
>
> Darren
>
Reply all
Reply to author
Forward
0 new messages