4
I created a directory with 3 modules. As below:
operacoes
__init__.py
soma.py
media.py
In my file __init__.py
I have the following code:
from media import *
The module soma.py
is used within the media.py
, then I’ll have the import
of it within the media. But this is ok.
My doubt is due to the error that is giving in from <module> import *
, which is as follows:
File "C: Users Jaqueline Workspace python3 lib site-Packages operacoes__init__.py", line 1, in from media import * Modulenotfounderror: No module named 'media'
I’m doing the import
wrong for Python 3? Is there anything else that could cause this error? I can’t understand what is wrong.
Ok. The fact is that I’m working on a package that I’m going to use in another application, and this package initializes some things in the project. I gave a simpler example, like operations. I would like to keep the init in my project, the problem is that I don’t know how to write the
from ... import ...
. Always give me the errorModuleNotFoundError: No module named '<module>'
. What is the right way to write?– user199858
Hi, I had a similar problem. Check two things: i) The directory name has to be different from the file name (eg.py operations/operations gives error). ii) PYTHONPATH has to be configured to run on the command line.
– Taciano Morais Silva