1

I have looked into other similar posts, but could not find an answer.

So,

Here is the structure of the project I am working on:

lyrics/__init__.py
lyrics/functions.py
manifold.py

When I execute manifold.py with this command:

./manifold.py

it calls:

import lyrics as lyr

which in turn calls init.py, which calls:

from lyrics import *
import functions

Here is the error that I get:

Traceback (most recent call last):
  File "./manifold.py", line 20, in <module>
    import lyrics as lyr
  File "/g../__init__.py", line 2, in <module>
    import functions
ModuleNotFoundError: No module named 'functions'

Any idea where the error comes from ?

Thanks

RandomFellow
  • 317
  • 1
  • 9

1 Answers1

1

If you want to import relatively, you have to add the . before functions, i.e. from . import functions

The import there works similar to unix: The single dot is for the current directory. If you put two dots (..) you go up one level, three dots (...) goes up two levels and so on.

If you want to go absolute, then from lyrics import functions should work.

Christian
  • 1,437
  • 2
  • 8
  • 14
  • Sorry but this does not work, I get the error: import .functions SyntaxError: invalid syntax – RandomFellow Jul 14 '22 at 12:29
  • @RandomFellow I'm sorry, I made a mistake. It should be `from . import functions`. I corrected that. – Christian Jul 14 '22 at 12:32
  • function.py file is on the same directory as __init__.py, yet *import .fucntions* does not work, it creates the error: import .functions SyntaxError: invalid syntax – RandomFellow Jul 14 '22 at 12:32
  • @RandomFellow As the duplicate shows, it should probably be `from . import functions` – Tomerikoo Jul 14 '22 at 12:46