Answer the question
In order to leave comments, you need to log in
Why doesn't python see the module even though __init__.py is there?
Project structure (Flask):
blog:
client:
*files
server:
blog_app:
__init__.py
*files
test:
test1.py
from blog_app import app
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from .config import Config
app = Flask(__name__)
app.config.from_object(Config)
app.debug = True
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from blog_app import main, models
ModuleNotFoundError: No module named 'blog_app'
Answer the question
In order to leave comments, you need to log in
Python just doesn't know that the server directory (and for test1.py is "..") can be searched for modules and packages.
Do this:
sys.path.append('..') in test1.py and it will be possible to import your package in it if you run it directly (test1.py)
When importing, Python looks for modules in the paths listed in sys.path .
One solution for you is to make a normal setup.py and then install it in editable mode (pip install -e .).
So the folder where the package is located will be added to sys.path and it will be imported from anywhere.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question