Closed rjmcguire closed 12 years ago
I'm afraid I haven't been able to reproduce this error. Relative imports are working correctly for me. Can you provide a test case? Here's what I tried:
import reloader
reloader.enable()
import json
... which correctly imports the JSONEncoder
class from the relative .encoder
module.
Furthermore, it looks like the ImportError
in your traceback is being thrown by the base import function (generally builtins.__import__
). Could there be another import hook that's in play here?
Thanks for taking a look. I don't have anything else messing with the import system as far as I know. I'll see if I can reduce a test case.
Cheers,
On Tue, Apr 10, 2012 at 8:31 PM, Jon Parise < reply@reply.github.com
wrote:
I'm afraid I haven't been able to reproduce this error. Relative imports are working correctly for me. Can you provide a test case? Here's what I tried:
import reloader reloader.enable() import json
... which correctly imports the
JSONEncoder
class from the relative.encoder
module.Furthermore, it looks like the
ImportError
in your traceback is being thrown by the base import function (generallybuiltins.__import__
). Could there be another import hook that's in play here?
Reply to this email directly or view it on GitHub: https://github.com/jparise/python-reloader/issues/8#issuecomment-5052887
I get a very similar error when importing json. I also get errors importing nltk, numpy, and zmq. I've copied them all into a gist here: https://gist.github.com/2364371 I have no problem importing these packages if reloader is not used.
I'm embarrassed to say that, after much head scratching, I realized that this issue was fixed months ago (in git) but was never included in a PyPI release. This is fixed now, so if you grab version 0.3, everything should work as expected.
Thanks, pip version now works for me.
On ubuntu 12.04 using python-reloader as the importer causes relative imports to fail. Example is from: Traceback (most recent call last): ... File "/usr/local/lib/python2.7/dist-packages/reloader.py", line 135, in _import _baseimport(name, globals, locals, fromlist, level) File "/home/rmcguire/Documents/Programming/Projects/clearformat_smtplogger_web/pyweb/session.py", line 5, in
import json
File "/usr/local/lib/python2.7/dist-packages/reloader.py", line 135, in _import
_baseimport(name, globals, locals, fromlist, level)
File "/usr/lib/python2.7/json/init.py", line 109, in
from .encoder import JSONEncoder
ImportError: cannot import name JSONEncoder
changing "from .encoder import JSONEncoder" to "from json.encoder import JSONEncoder" fixes the problem.
Does python-reloader support relative imports?