I've been following the instructions on the following site:
https://flask.palletsprojects.com/en/2.0.x/patterns/packages/
I've been getting the following error:
web_1 | Error: While importing 'passless', an ImportError was raised:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 256, in locate_app
web_1 | __import__(module_name)
web_1 | File "/app/passless/__init__.py", line 4, in <module>
web_1 | import passless.views
web_1 | ModuleNotFoundError: No module named 'passless.views'
setup.py
from setuptools import setup
setup(
name='passless',
packages=['passless'],
include_package_data=True,
install_requires=[
'flask',
],
)
__init__.py
from flask import Flask
app = Flask(__name__)
import passless.views
docker-compose.yaml
version: "3"
services:
web:
build: .
image: passless
environment:
FLASK_DEBUG: 1
FLASK_APP: passless
FLASK_ENV: development
ports: ['5001:5000']
volumes: ['.:/app']
Here is the directory structure I am using:
/passless
setup.py
/passless
__init__.py
index.py
/static
style.css
/templates
layout.html
index.html
login.html
Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.9-slim-buster
WORKDIR /app
COPY . .
RUN pip3 install -e .
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
Rename index.py to (or add) views.py:
from passless import app
@app.route('/')
def index():
return 'Hello World!'
Directory structure:
/passless
docker-compose.yaml
Dockerfile
setup.py
/passless
__init__.py
- index.py
+ views.py
https://stackoverflow.com/a/15368107/16409598 this will fix your problem, and I am not a big fan of python but logically speaking according to your words,
*web_1 | Error: While importing 'passless', an ImportError was raised:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 256, in locate_app
web_1 | __import__(module_name)
web_1 | File "/app/passless/__init__.py", line 4, in <module>
web_1 | import passless.views
web_1 | ModuleNotFoundError: No module named 'passless.views'*
you are trying to load/use a file that does not exist, try creating the file then calling it, or maybe import passless.py!
**REMINDER: I AM NOT a fan of python, just here to help :)**
Best Regards