Python import package - __init__.py is not executed

700 Views Asked by At

I know there are several similar topics discussed here, but none of them was helpful for this problem.

I have the following file structure:

lib/
      Linearalgebra/
                              __init__.py
                              vector.py

The lib/ directory is in my PYTHONPATH, I doublechecked it by printing sys.path.

The __init__.py file contains the code from vector import Vector.
The vector.py file contains a class called Vector

Now if i run the following script

import Linearalgebra
v1 = Linearalgebra.Vector([1, 1])

I get AttributeError: 'module' object has no attribute 'Vector'

When I run this code in order to check what actually gets imported

import Linearalgebra
print Linearalgebra

I get <module 'Linearalgebra' from '...lib/Linearalgebra.py'>

I think I should get <module 'Linearalgebra' from '...lib/Linearalgebra/__init__.py'>

Why is __init__.py not executed?

0

There are 0 best solutions below