Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python project not importing a local module

I have a python project using Flask and I have a form I have setup in a module I called forms. I test my app in Windows and it works just fine. I then update my project on Debian where I use Apache2 to run the project. There I get the error: ModuleNotFoundError: No module named 'forms'

My project is organized like so:

flaskapp.wsgi
flask_app
    __init__.py
    forms.py

And __init__.py starts with:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from flask import Flask, redirect, url_for, request, render_template, send_from_directory, abort
from requests import Request, Session
from forms import OrderForm

I checked the sys.path with:

import sys
print(sys.path)

when using the python console and got:

['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']

I’m not sure what I need to do to get it to use forms as a module

>Solution :

Try from .forms import OrderForm.
This is referencing to the same folder. Otherwise flask_app.forms should work too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading