[Pydev-code] Executable .pth files work as expected in the CLI Python interpreter but not in PyDev
Brought to you by:
fabioz
|
From: Andornaut <and...@gm...> - 2012-02-09 16:56:00
|
I ran into an issue recently when trying out the Pyramid web
framework. It has a dependency on zope.sqlalchemy and a couple of
other zope.* libs. These dependencies are installed into the
site-packages/ directory:
zope
/deprecation
/interface
/sqlalchemy
zope.deprecation-3.5.0-py2.7.egg-info
zope.deprecation-3.5.0-py2.7-nspkg.pth
zope.interface-3.8.0-py2.7.egg-info
zope.interface-3.8.0-py2.7-nspkg.pth
zope.sqlalchemy-0.7-py2.7.egg-info
zope.sqlalchemy-0.7-py2.7-nspkg.pth
Using a CLI python interpreter, I am able to import zope or zope.sqlalchemy
$ python
>>> import zope
>>> print zope
<module 'zope' (built-in)>
>>> import zope.sqlalchemy
>>> print zope.sqlalchemy
<module 'zope.sqlalchemy' from
'/home/andornaut/.virtualenvs/pyramid/local/lib/python2.7/site-packages/zope/sqlalchemy/__init__.pyc'>
Whereas, from within Eclipse(PyDev) I am unable to import "zope" or
"zope.sqlalchemy".
This discrepency in behavior looks to be do to some magic happening in
the.pth file:
$ cat site-packages/zope.sqlalchemy-0.7-py2.7-nspkg.pth
import sys,types,os; p =
os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',)); ie =
os.path.exists(os.path.join(p,'__init__.py')); m = not ie and
sys.modules.setdefault('zope',types.ModuleType('zope')); mp = (m or
[]) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
Most of the other Pyramid dependencies are picked up by PyDev, but all
of the ones that do not include an __init__.py file in their root
directory are not picked up ("Repoze" is another example).
I can work around this by adding __init__.py files to the root
directories of all of the libs that PyDev does not pick up, but this
is obviously not a great solution. (Or perhaps someone can suggest a
more clean workaround in the meantime?)
Ideally, PyDev would work the same as the command line Python
interpreter - by executing the .pth files and working with whatever
"magic" occurs therein.
Thanks.
|