'ModuleNotFoundError: No module named 'funciones' (Python)
I'm trying to create some diccionary with some functions for some repetitive tasks where I work, and now when I try to use any function on the dicc I have this error. I'm also learning python, there's like 2 weeks i'm proggraming in this language, so if anybody can help me to approach the problem in a more specific way, I'll be very grateful.
That's the folders structure: folders structure
here is how I'm importing the functions, storing and invoking function
#Funciones Cred Now ------------------
from funciones.credNowFunciones.CredNowLoanCargar import credNowLoanCargar
from funciones.credNowFunciones.CredNowLoanCargar import credNowLoanCargarYComparar
from funciones.credNowFunciones.CredNowLoanAcumulable import credNowLoanAcumulable
credNowDict = {
"cargarLoan": credNowLoanCargar,
"cargarYCompararLoan": credNowLoanCargarYComparar,
"loanAcumulable": credNowLoanAcumulable
}
#Invocar funciones
credNowDict['cargarLoan']('archivos/excels/credNow/1-100-CXXXNXw_1102.xlsx',
'archivos/generadosPorEmpresa/credNowGenerados/crxxNxxnxCargar.xlsx')
Solution 1:[1]
The from package.subpackage.module import object structure only works if package and subpackage are valid packages - that is, they are in a directory on the PYTHONPATH or in the same directory as the __main__ file, containing a file called __init__.py.
Because neither funciones nor credNowFunciones contain a file called __init__.py, they do not count as packages and cannot be imported properly. To solve this, simply add an empty __init__.py file into each of the folders which you want to be able to import from, so the folder structure of funciones becomes like this:
funciones/
__init__.py
credNowFunciones/
__init__.py
CredNowLoanAcumulable.py
CredNowLoanCargar.py
edemsaFunciones/
__init__.py
...
Also note that if the python script you are importing the objects into is not in the same directory as funciones, you need to make sure funciones is in a directory which is on your PYTHONPATH. See here for more info.
For more information on Python packages, see here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lecdi |
