0

I have the fallowing directory tree:

foo_project/
├── foo/
│   ├── foo_conversor.py
│   ├── __init__.py
│   └── __pycache__/
│  
├── foo.py
└── __pycache__/

I'm trying to import a class named Foo that is inside foo.py at foo_conversor.py, I've tried a lot of ways but I can't understand how to do this import. Can someone help me? It's any problem with __init__.py?

I already tried:

from ..foo import Foo
from .. import Foo
from . import Foo
from foo import Foo

I've already read a lot fo answers here but none helped me.

Otavio Henrique
  • 100
  • 1
  • 6
  • I recently answered a really similar question to this [here](https://stackoverflow.com/questions/52335995/error-when-importing-module-from-a-different-folder-in-the-same-parent-directory/52336239#52336239). It is because Python only looks inside your `/foo` directory for imports. You either have to start the program from a file inside `foo_project` or add the folder to the `sys.path`. – Karl Sep 15 '18 at 19:04
  • 1
    Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – Mirco De Zorzi Sep 15 '18 at 19:05
  • You have both a module `foo` (the file `foo.py`) **and** a package called `foo` (the directory `foo/` plus the `__init__.py` file). When you `import foo` in any of the variations you tried, the package will be chosen over the module. So you can't import the module when they are named the same. – Wombatz Sep 15 '18 at 19:08
  • You need to either change the name of the module `foo` or change the file name `foo.py`. – yogkm Sep 15 '18 at 19:38

0 Answers0