External Libraries...

48 views
Skip to first unread message

JohnMc

unread,
Jul 1, 2009, 5:19:36 PM7/1/09
to web2py Web Framework
I have a problem that has me stumped. Code snippet below. Attempting
to import two external libraries that I built. I receive a ticket
indicating module not found in app/module folder which is to be
expected. I looked in the manual, AlterEgo and this group. There was a
reference back in April to this but it does not seem to address my
issue.

What is the proper format to reference an external python library from
Web2Py?

Thanks!

JohnMc

In Controller:
------------------------
# try something like
#Import pyquery and lxml components
from lxml import etree
from pyquery import PyQuery as pq

#Private functions
...
...

mdipierro

unread,
Jul 1, 2009, 5:23:49 PM7/1/09
to web2py Web Framework
You code below is correct, you just have to make sure the libraries
are in the search path. If you use third party libraries you should
run web2py from source else you may run into trouble because you would
have two python interepreters (the one that ships with binaries and
the one you used to install the libs).

JohnMc

unread,
Jul 1, 2009, 5:35:25 PM7/1/09
to web2py Web Framework
Generally use source as the test box is a linux machine. But thanks
for the tip.

I'll go check my paths.

That does bring up a followup question. For Web2Py is the search
heirarchy ==

controller-->app/module/-->python path ?

Thanks.

JohnMc

mdipierro

unread,
Jul 1, 2009, 5:51:12 PM7/1/09
to web2py Web Framework
No app/modules and controllers folder are not in the paths

try print sys.path to be sure

note: do not modify you sys.path in the web2py apps of you run into
memory leaks and threading issues. If you really need to, paths should
only be modified in web2py.py

Massimo

Yarko Tymciurak

unread,
Jul 1, 2009, 6:28:31 PM7/1/09
to web...@googlegroups.com
See also my recent reply to Xie on a recent thread:

[web2py:25413] Re: confusion about web2py's MVC namespace

JohnMc

unread,
Jul 2, 2009, 11:28:30 AM7/2/09
to web2py Web Framework
Yarko,

Read your reply to Xie. I come to realize the situation I am
experiencing is a little different. lxml is loaded as a package not a
module. There is a python egg directory

.../site-packages/lxml-2.2.2-py2.5-linux-686.egg/...

contained in that directory is .../lxml/__init__.py. There is no
lxml.py module to load. Now checking sys.path it reports the /site-
package/...egg directory is in the path. Interestingly, if I load up
the controller .py file in ipython the lxml import works and lxml
functions properly.

I have only dug into a few of the Web2Py internals so I am somewhat at
a loss as to how to proceed.

JohnMc

On Jul 1, 5:28 pm, Yarko Tymciurak <yark...@gmail.com> wrote:
> See also my recent reply to Xie on a recent thread:
>
> [web2py:25413] Re: confusion about web2py's MVC
> namespace<http://groups.google.com/group/web2py/msg/1fcecf8cf3456bbd>

JohnMc

unread,
Jul 2, 2009, 12:12:59 PM7/2/09
to web2py Web Framework
Yarko,

Read your discussion with Xie. I have come to realize my situation is
a little different. lxml is a package not a module. Hence there is no
lxml.py to discover. Looking at the situation there is a directory --

.../site-packages/lxml-2.2.2-py2.5-i686.egg/...

and this directory is in the path according to sys.path. There is
a .../lxml sub that contains the file __init__.py. The interesting
thing is if I bring up ipython and load the controller .py file the
imports of lxml works fine and the calls to lxml work as advertised.

As I have only dug through only a few points of web2py internals I am
somewhat of a loss as to how to proceed.

JohnMc

On Jul 1, 5:28 pm, Yarko Tymciurak <yark...@gmail.com> wrote:
> See also my recent reply to Xie on a recent thread:
>
> [web2py:25413] Re: confusion about web2py's MVC
> namespace<http://groups.google.com/group/web2py/msg/1fcecf8cf3456bbd>

JohnMc

unread,
Jul 3, 2009, 4:54:50 PM7/3/09
to web2py Web Framework
"You code below is correct, you just have to make sure the libraries
are in the search path."

Right as always, Massimo is. However I did not feel comfortable
flopping around in web2py.py. So after a little research I redicovered
the python .pth file. I added a lxml.pth file to .../site-packages
pointing to the proper subdirectory to be added to the pythonpath. It
worked like a charm.

Might be useful to someone. More information is available in the
site.py file in python root dir.

On Jul 1, 4:23 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:

Yarko Tymciurak

unread,
Jul 3, 2009, 6:57:37 PM7/3/09
to web...@googlegroups.com
On Fri, Jul 3, 2009 at 3:54 PM, JohnMc <maruadv...@gmail.com> wrote:

"You code below is correct, you just have to make sure the libraries
are in the search path."

Right as always, Massimo is. However I did not feel comfortable
flopping around in web2py.py. So after a little research I redicovered
the python .pth file. I added a lxml.pth file to .../site-packages
pointing to the proper subdirectory to be added to the pythonpath.  It
worked like a charm.

Might be useful to someone. More information is available in the
site.py file in python root dir.

 Yep - correct python installation of packages is key...


Reply all
Reply to author
Forward
0 new messages