ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package - python-3.x

what is this error please help me iam getting it in python & iam new ? iam using the open source code of simso simulator
ModuleNotFoundError: No module named 'main.MetricsWindow'; 'main' is not a package

This error: ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package may also occur if you have named the main program file you created as __main__.py and try to run it as python __main__.py or another file has the name __main__.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path.
In this case, rename your program file so that its name does not equal with the name of the imported module.

Related

ModuleNotFoundError: No module named 'module' while importing my own module VsCode MacOs Python 3.10

Structure:
|--folder/
|--a.py
|--main.py
When loading module 'main' into module 'a'
#a.py
import main
the following error occurs - ModuleNotFoundError: No module named 'main'.
PyCharm copes with this task, but VSCode does not. What's the matter?
Looking at your directory structure, I presume that a.py and main.py are in different directories. If that is the case, then the answers to [this question][1] should be useful. To elaborate a bit further, you can use the sys module to specify the path to the other module (main.py) i.e. if main.py is in a different directory from a.py.
import sys
sys.path.append('/path_to_main_module_directory/')
import main
print("This import is for the main module")
I hope this helps!
[1]: Importing files from different folder

How do I handle custom modules when creating an exe with PyInstaller?

Using PyInstaller I created a executable from a python script as follows:
pyinstaller --onefile pythonScriptName.py
However, when I run the executable I get an error ImportError: No module named 'MyModule'.
'MyModule' is a placeholder name for a custom module I use in the script. So I'm assuming that PyInstaller didn't package up the custom modules. Is there some way to get it to do that?
I found the --collect-submodules flag to be helpful when getting an import module error.
I just specify the folder name under which all my modules are and pyinstaller collects all the imports automatically.
something like this:
pyinstaller --collect-submodules <folder-name>

ModuleNotFoundError: No module named 'message_board'

I ran this command on the terminal
coverage run test_message_board_urls.py
and I got an error
ModuleNotFoundError: No module named 'message_board
I have a statement in the test_message_board_urls.py file that says
from message_board.views import xxx,yyy,zzz
Thanks for your help
It does look for the module message_board in order to import the functions xxx, yyy and zzz from the package views, but it does not find the module message_board. Either you have not installed the module message_board or it is located at a path, where it is not found by the script.

ModuleNotFoundError: No module named 'app'

Whenever I run this script under the folder app/klarna_basic/klarna_basic_test.py, I always get the error:
ModuleNotFoundError: No module named 'app'.
The code used for importing is,
from app.Fortnox import Fortnox
Fortnox.py is located in app(app/Fortnox.py) folder.
See the image below.
What seems to be problem on this one?
it looks like Fortnox.py is inside the subfolder klarna_basic
from klarna_basic.Fortnox import Fortnox
orimport klarna_basic.Fortnox

Python3 module pakaging files structure and init file

I have Python module with single file and single function inside the file. I've uploaded it to pypi, and I used following structure to package it, but when I called the function which it inside module file I received this error:
AttributeError: module 'effInput' has no attribute 'ask'
('ask' is name of function).
Module package structure :
|--effInput
|--__init__. py
|--effInput.py (module file)
|--setup.py
|--readme.txt
|--LICENSE
init.py file:
import effInput
name="EffInput"
What I did wrong?
When you do it that way you have to call effInput.effInput.ask instead of effInput.ask. If you did from effInput import * in your __init__.py it should work as intended.

Resources