Importing like-named modules when calling install_package

6 views
Skip to first unread message

project2501

unread,
Feb 26, 2017, 9:15:43 AM2/26/17
to ipopo-users
Hi,
  I'm experiencing an oddity and am not sure if its because of something I'm doing.

I am calling 

context.install_package('path/to/top/level/stuff')

Within that package structure is a module (with ipopo stuff in it), located here:

find.components.ml.pattern

Within that module it tries to import the separate module pattern.vector , a 3rd party package. Like below

from pattern.vector import Document, Model, HIERARCHICAL


ipopo then complains about this:


WARNING:pelix.main:Error visiting find.components.ml.pattern: Error installing bundle find.components.ml.pattern: No module named vector

It seems that it is interpreting pattern.vector as being within the find.components.ml.pattern module, which it is not.

Regrets if I missed something obvious in the documentation about this.

Darren

project2501

unread,
Feb 26, 2017, 9:23:55 AM2/26/17
to ipopo-users
I change the install_package path to the absolute root module path and it works now. Before it was going 2 module levels deep (inadvertently) in the path and that's when the error happened. weird.

Thomas Calmant

unread,
Feb 26, 2017, 1:43:49 PM2/26/17
to ipopo...@googlegroups.com
Hi,

This is a tricky problem: in install_package, iPOPO adds the given path as the first entry of sys.path to ensure that this package, and only this version, will be imported by Python.
As a result, imports of modules/packages with the same name will fail, as the priority is given to the current package, not to the third-party library.

If you're using Python 2, you could try to enable absolute imports: from __future__ import absolute_import as it changes the behaviour in similar cases.

Regards,
Thomas


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "ipopo-users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse ipopo-users+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

project2501

unread,
Mar 3, 2017, 8:42:22 AM3/3/17
to ipopo-users
Thank you.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse ipopo-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages