ModuleNotFoundError: No module named 'app' - python-3.x

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

Related

How to import a module from parent directory within a subdirectory

I was working on a simple project, bike_rentals. I thought all was well until I began writing test files for the project.
I created a new directory and name it TestBikeRental and saved it within the BikeRentals directory, which contained the scripts for my project. I created the file init.py within the BikeRentals and TestBikeRentals directory to make them each be a package. Within the top directory is the script run_script.py that I use to run the modules\scripts contained in the package BikeRentals.
Directory structure
The problem comes up when I try to import the py script db_connection (underlined in yellow), within the Test_bike_rentals.py.
This is how tried to imported db_connection.
Importing db_connection
After numerous and numerous attempts, the errors that I kept receiving were these two:
from BikeRentals.BikeRentals.db_connection import Connect
ModuleNotFoundError: No module named 'BikeRentals'
from..db connection import Connect
ImportError: attempted relative import with no known parent package
To view the sourcecode in github repo:
https://github.com/Brownred/Python-and-SQL
I tried to import a module but got an error after numerous attempts. I was expecting no error when it comes to importing a module.

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

ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package

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.

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.

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