Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

318
Vistas
Import error when restructuring test application using Flask

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"]
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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
over 4 years ago · Santiago Trujillo Denunciar

0

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
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda