RDFLib/rdflib — Issue #179: ImportError: No module named term
Author: gjhiggins
Created: 2012-02-20 08:34:32+00:00
State: open

kaska...@gmail.com, 2011-09-27T23:17:41.000Z

What steps will reproduce the problem?
1. hg clone https://code.google.com/p/rdflib/
2. mv rdflib/rdflib /tmp/extras
3. touch /tmp/extras/__init__.py
4. execute python from /tmp directory and execute: from extras import rdflib

What is the expected output?
no output, just rdflib loaded

What do you see instead?
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from extras import rdflib
Traceback (most recent call last):
File "", line 1, in
File "extras/rdflib/__init__.py", line 64, in
from rdflib.term import URIRef, BNode, Literal, Variable
ImportError: No module named term

What version of the product are you using? On what operating system?
Using last source from hg repository on ubuntu 11.04

Please provide any additional information below.
Pending to test in other environments. I use to follow the same steps with previous version of rdflib (2.4) with no problem at all.
Thanks in advance. I love rdflib.

Comment 1 by gjhigg...@gmail.com
If I understand it correctly, your approach relies on Python<=2.5 behaviour in which relative imports were the default. In Python>=2.6 that default has been changed in favour of absolute imports.

I don't know of any crufty, encapsulating meta-package trick that would allow you to continue your strategy uninterrupted. I was able to confirm that serial replacement of "import rdflib.X" with "import .X" does eventually result in a successful import of rdflib but I wasn't able to take it any further than that.

If there are no other options available to you then the only suggestion I can make is that you create a separate clone of rdflib, edited to perform relative imports as described above (assuming that it satisfactorily executes your tests) and to use that clone for your testing.

Sorry I can't be of more help.

Comment 2 by kaska...@gmail.com
Thanks a lot for pointing me in the right way. I hadn't noticed this change in Python. I've been reading PEP 328 (Absolute and Relative Imports) and it seems there is nothing to do. As you say Python 2.5 was the last version allowing relative imports.

It's not a big problem for me to use absolute imports but I was happiest building my own bundles and test them in other distros or shared webservers.

I'm not an python expert but I wish if instead:
from __future__ import absolute_import
I could use:
from __past__ import relative_import

Much appreciated.

Comment 3 by gromgull
not really a bug.