Quelle est la bonne façon de corriger cette erreur ImportError?
J'ai la structure de répertoires suivante:
/home/bodacydo
/home/bodacydo/work
/home/bodacydo/work/project
/home/bodacydo/work/project/programs
/home/bodacydo/work/project/foo
Et je suis dans l'annuaire
/home/bodacydo/work/project
Maintenant si je tape
python ./programs/my_python_program.py
Je reçois instantanément
ImportError: No module named foo.tasks
Le ./programs/my_python_program.pycontient la ligne suivante:
from foo.tasks import my_function
Je ne peux pas comprendre pourquoi python ne trouvera pas ./foo/tasks.py- il est là.
Si je le fais à partir du shell Python, cela fonctionne:
python
>>> from foo.tasks import my_function
Cela ne fonctionne que si je l'appelle via un python ./programs/my_python_program.pyscript.