No module named 'widgets', but it is a directory, not a module
-
Literally that: adding a file named
__init__.py
in the folder. However it might not be needed anymore with Python 3.@SGaist the problem persist, it said that there isn’t any module name “Model”, but Model is a folder. Inside it there is the
Standard_Item
file that i want to import:From Model.standard_item import StandardItem ModuleNotFoundError: No module named ‘Model’
Do you think it could be a venv problem?
-
Shouldn't that be:
from .Model.standard_item import StandardItem
?
Notice the starting
.
. -
Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?
-
Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?
-
Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?
@SGaist here I am. I solved the problem by adding a line of code at the beginning of the main file:
sys.path.append(r’/Users/[user]/Desktop/[folder name]’)
It identifies the path to the folder that contains the other subfolders. Thanks for your time!
-
When using that technique you should rather determine the location of the current script using
__file__
so that you don't hard code the path in it. -
@SGaist here I am. I solved the problem by adding a line of code at the beginning of the main file:
sys.path.append(r’/Users/[user]/Desktop/[folder name]’)
It identifies the path to the folder that contains the other subfolders. Thanks for your time!
@Mindful i have this problem.~
you can explain better how you solve? -
@Mindful i have this problem.~
you can explain better how you solve?@Filipe_Portugal
See https://www.geeksforgeeks.org/file-a-special-variable-in-python/ for__file__
. Use that if you need the path to the Python script file/directory rather than hard-coding it. -
@SGaist of course! What part of the code would be more useful for you? I could paste it here
@Mindful i have this problem.~
you can explain better how you solve?