No module named theapp - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: No module named theapp (/thread-33914.html) Pages:
1
2
|
No module named theapp - Clives - Jun-09-2021 Greetings, I am developing a Flask application, but keep getting an error from: import theapp and from theapp import app?? This is the folder structure: I have a folder called theapp, with _init_, db and routes.py Appreciate any pointers where I am going wrong?? Thanks, Clive In run.py the code is: from flask import Flask from theapp import app #import theapp.routes app = Flask(__name__) if __name__ == "__main__": app.run(debug=True)In routes.py import flask from flask import Flask from flask import render_template, request, redirect, send_file,url_for, flash from theapp import app #import app #from theapp.db import conn, text, exc#from theapp.helper import getcriteria, getyear, create_financial_year, getquarter, updatefield, getresults, deleterecord, log, get_isodate, #from theapp.helper import * #from theapp.forms import * #from theapp.models import User #from theapp.loginsystem import * #from theapp.view_programme import * import csv import os import datetime as dt import urllib.request import logging import datetime import hashlib import random import json @app.route('/') @app.route('/index') def index(): return "Hello, World!" RE: No module named theapp - topfox - Jun-09-2021 It sounds like theapp is in a location that is not being searched. This is a useful guide to checking the path: https://www.dummies.com/programming/python/how-to-find-path-information-in-python/ RE: No module named theapp - Clives - Jun-09-2021 Thanks for you msg, Ok, from your post I presume that I need to load theapp module in the site-packages?? If the code is not compiled, how do I save it to the site-packages?? Regards, Clive RE: No module named theapp - topfox - Jun-09-2021 If you are installing modules using pip, then they will be automatically put in the site-packages folder. If theapp is your own module, then it needs to be located in one of the searched locations so that python can find it. Does your __init__.py include a line like "from .theapp import *"? You'll need that. RE: No module named theapp - Clives - Jun-10-2021 Hi topfox, Thanks for the message. I added the import to __init__.py Get an error message for .theapp Does that mean that I have to copy the theapp folder to site packages??? Thought I would copy a compiled theapp.py to site packages. Thanks Clive from flask import Flask app = Flask(__name__) app.config.from_object('config') app.jinja_env.add_extension('jinja2.ext.do') from .theapp import *The error msg:
RE: No module named theapp - Clives - Jun-10-2021 Really weird I had to use import Flasktest.theapp, that works. In the past I just used theapp, not FlaskTest.theapp?? RE: No module named theapp - Clives - Jun-10-2021 Now I am getting an new error.. All the modules are installed??
RE: No module named theapp - Clives - Jun-10-2021 It seems that the error points to the werkzeug module?? Weird?? PYTHONPATH = C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38
RE: No module named theapp - Clives - Jun-10-2021 In a previous Flask app, I imported theapp and it worked.. In this app I had to use: from flask import Flask app = Flask(__name__) app.config.from_object('config') app.jinja_env.add_extension('jinja2.ext.do') import FlaskTestPYTHONPATH=C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38 When I run sys.path I get: C:\Users\tmpgcesn\PycharmProjects\Flask\FlaskTest\theapp C:\Users\tmpgcesn\PycharmProjects\Flask C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\python38.zip C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\DLLs C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38 C:\Users\tmpgcesn\AppData\Roaming\Python\Python38\site-packages C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib\site-packages C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib\site-packages\win32 C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib\site-packages\win32\lib C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib\site-packages\PythonwinI am getting an error msg from __init__.py??
RE: No module named theapp - Clives - Jun-10-2021 I opened the project in Visual Code, it ran without any errors. Appears that PyCharm Community version is the problem, not the code?? Weird!! |