Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No module named theapp
#1
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!"

Attached Files

Thumbnail(s)
   
Reply
#2
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/pyth...in-python/
Reply
#3
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
Reply
#4
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.
Clives likes this post
Reply
#5
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:
Error:
Traceback (most recent call last): File "C:/Users/tmpgcesn/PycharmProjects/Flask/FlaskTest/theapp/__init__.py", line 5, in <module> from .theapp import * ImportError: attempted relative import with no known parent package Process finished with exit code 1
Reply
#6
Really weird

I had to use import Flasktest.theapp, that works.

In the past I just used theapp, not FlaskTest.theapp??
Reply
#7
Now I am getting an new error.. Angry
All the modules are installed??

Error:
- missing __init__.py in a package; - package or module path not included in sys.path; - duplicated package or module name taking precedence in sys.path; - missing module, class, function or variable; Debugged import: - 'config' not found. Original exception: ModuleNotFoundError: No module named 'config' Process finished with exit code 1
İmage

Attached Files

Thumbnail(s)
   
Reply
#8
It seems that the error points to the werkzeug module??
Weird??

PYTHONPATH = C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38

Error:
Traceback (most recent call last): File "C:\Users\tmpgcesn\AppData\Local\Programs\Python\Python38\lib\site-packages\werkzeug\utils.py", line 865, in import_string __import__(import_name) ModuleNotFoundError: No module named 'config'
Reply
#9
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 FlaskTest
PYTHONPATH=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\Pythonwin
I am getting an error msg from __init__.py??
Error:
- missing __init__.py in a package; - package or module path not included in sys.path; - duplicated package or module name taking precedence in sys.path; - missing module, class, function or variable; Debugged import: - 'config' not found. Original exception: ModuleNotFoundError: No module named 'config'
Reply
#10
I opened the project in Visual Code, it ran without any errors.
Appears that PyCharm Community version is the problem, not the code??
Weird!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ModuleNotFoundError: No module named "requests" BushFacts 1 5,143 Jan-13-2020, 06:49 AM
Last Post: perfringo
  Django getting ModuleNotFoundError: No module named '=' Malt 0 2,965 Aug-30-2019, 08:34 AM
Last Post: Malt
  No module named flask_themes voipsense 4 4,838 Feb-25-2019, 06:54 PM
Last Post: voipsense
  About .profile and ImportError: No module named RicardoAbdala 1 3,152 Aug-28-2018, 05:32 AM
Last Post: buran
  ImportError: No module named django.core.exceptions in google app engine timtinan37 4 4,974 Jun-18-2018, 01:34 PM
Last Post: Larz60+
  ImportError: No module named '_sqlite3' armanmax11 5 21,483 Dec-16-2017, 02:13 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020