You Are Here Home > November 2008

November 2008

Python ImportError: cannot import name X

This was strange, I had a bunch of classes in a file and was trying to import one of them from a file in a child folder.

The package looked like this:

/main_classes.py <– “import child” was in here way on top
/child/__init__.py <– For every file in this folder, import it
/child/some_file.py <– Import a class in main_classes.py *Error*

The reason was that I was doing “import child” way on top before implementing the class I was importing in some_file.py.

I moved the “import child” line from the top of the main_class.py to the constructor of the class I was implementing and it fixed the issue.

I hope this made sense :) (and I know it will to the person with this problem ;) )

Python ImportError: cannot import name X
Comments (13)   Filed under: Python   Posted by: Hamid

My favorite TED talk

Watch all of it ;)

My favorite TED talk
Comments (0)   Filed under: Fun,General,Space,Technology   Posted by: Hamid
« Newer PostsOlder Posts »