Reputation: 153
I keep getting the error below after trying many different ways of importing files in Python.
File "/Users/mengjial/Documents/Python_Programs/flask-rethink/flask-rethink/app/views.py", line 3, in <module>
import forms
ModuleNotFoundError: No module named 'forms'
The structure of the /Users/mengjial/Documents/Python_Programs/flask-rethink/flask-rethink/app/
folder is as below
.
├── __init__.py
├── __init__.pyc
├── __pycache__
│ ├── __init__.cpython-39.pyc
│ ├── forms.cpython-39.pyc
│ └── views.cpython-39.pyc
├── forms.py
├── models.py
├── templates
│ ├── base.html
│ └── index.html
└── views.py
Clearly forms.py
is parallel to views.py
in the same directory, and in views.py
I have
import sys
sys.path.append('f/Users/mengjial/Documents/Python_Programs/flask-rethink/flask-rethink/app/forms.py')
import forms
What went wrong for me?
Upvotes: 0
Views: 2039
Reputation: 679
In this case, maybe this should work:
from . import forms
I tried it, and worked fine.
Upvotes: 3