jparise / python-reloader

Dependency-based Python Module Reloader
http://www.indelible.org/ink/python-reloading/
MIT License
135 stars 27 forks source link

AttributeError when importing subpacket #16

Closed GIider closed 10 years ago

GIider commented 11 years ago

I have the following structure:

-- folder_a
|--- __init__.py

reloader.py
main.py

The init.py contains the following code: from os.path import dirname main.py has this:

import reloader
reloader.enable()

import folder_a

Running main.py fails:

C:\temp\foobar>python main.py
Traceback (most recent call last):
  File "main.py", line 4, in <module>
    import folder_a
  File "C:\temp\foobar\reloader.py", line 158, in _import
    base = _baseimport(name, globals, locals, fromlist, level)
  File "C:\temp\foobar\folder_a\__init__.py", line 1, in <module>
    from os.path import dirname
  File "C:\temp\foobar\reloader.py", line 166, in _import
    m = getattr(m, component)
AttributeError: 'module' object has no attribute 'path'
agates commented 10 years ago

Hi,

I ran into the same issue with import various things, such as multiprocessing. I've temporarily fixed this by catching the AttributeError:

try:
    m = getattr(m, component)
except AttributeError:
    pass

However I don't know much about the internals yet. It seems to continue working for me.

jparise commented 10 years ago

I'm afraid I can't reproduce this problem as described. Can you tell me which version of the code you're using?

Also, I suppose this could be related to the Windows environment in some way. I don't have easy access to a Windows machine at the moment. Maybe you could try this is a Unix-like machine to see if the problem also occurs there?

GIider commented 10 years ago

I just tried it again with the latest version on Github and Python 3.3.0. Still throws the same error:

C:\Users\Glider\Desktop\test>python main.py
Traceback (most recent call last):
  File "main.py", line 4, in <module>
  File "C:\Users\Glider\Desktop\test\reloader.py", line 158, in _import
  File "C:\Users\Glider\Desktop\test\folder_a\__init__.py", line 1, in <module>
  File "C:\Users\Glider\Desktop\test\reloader.py", line 166, in _import
AttributeError: 'module' object has no attribute 'path'

I will try this on one of the Linux boxes at work tomorrow and report back.

jparise commented 10 years ago

I think I was able to figure out what was going on. Please have a look at the latest code and let me know if it solves the problem on your end, too.

GIider commented 10 years ago

It works now, many thanks!