1

I’m trying to use a class from other folder.

I created an __init__.py file in all my folders. But I sill can’t import the class. I’m trying to import Vector class from ex02/vector,py to ex03/matrix.py

Here is the tree file

day01
.
├── README.md
├── __init__.py
├── ex00
│   ├── __init__.py
│   ├── book.py
│   ├── recipe.py
│   └── test.py
├── ex01
│   ├── __init__.py
│   └── game.py
├── ex02
│   ├── __init__.py
│   ├── pytest.py
│   └── vector.py
└── ex03
    ├── __init__.py
    └── matrix.py

I’m importing using this command:

from day01.ex02.vector import Vector

But I’m getting this error:

Traceback (most recent call last):
  File "matrix.py", line 1, in <module>
    from day01.ex02.vector import Vector
ModuleNotFoundError: No module named 'day01' 

The python code that is importing is this one:

https://pastebin.com/8AZAV6fv

And the one that I'm trying to import is this one

https://pastebin.com/BkYX9sc4

  • Does this answer your question? [Relative imports in Python 2.7](https://stackoverflow.com/questions/14132789/relative-imports-in-python-2-7) – dantechguy Jul 10 '20 at 00:05

0 Answers0