Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The fix is to make the WSGI target match the module and object your code actually exports. For a direct Flask instance, use a target such as gunicorn myapp:app. For an application factory, use gunicorn 'myapp:create_app()'. If the target looks correct, read the first traceback failure: a circular import, a module-name collision, or an exception during startup may have prevented app from being created.

What “cannot import name app” means

A WSGI server imports a Python module, then looks for the name after the colon in its target. In gunicorn package.wsgi:app, it imports package.wsgi and expects that module to expose an object named app. The error means Python found the module but could not provide that attribute. Usually, either the target names the wrong object or module initialization stopped before the object was assigned.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This differs from ModuleNotFoundError. A missing-module error means Python could not locate the module at all. “Cannot import name app” generally means the module was located, but the requested name is absent, misspelled, conditionally created, or never reached because another import failed first.

Flask itself is a WSGI application: a WSGI server calls the Flask object after the application has finished setup. A production command therefore imports an object or factory; it does not run the local development workflow for you.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

Use this diagnostic order

  1. Read the first traceback failure. Scroll to the earliest exception, not merely the final import line. A syntax error, missing dependency, configuration exception, or database connection failure earlier in the traceback can leave the module only partially initialized.
  2. Write down the exact target. Separate the module (left of :) from the exported name (right of :). For myapp.wsgi:application, those are myapp.wsgi and application.
  3. Open the target module and verify the name. Look for a top-level assignment such as app = Flask(__name__), or for a factory named create_app. Case and spelling matter.
  4. Test the import in the same environment. Activate the virtual environment and run the import from the same directory used by the process manager. For example:
python -c "from myapp import app; print(app)"
python -c "from myapp.wsgi import application; print(application)"

If either command fails, the problem is in Python imports or application initialization rather than in Gunicorn’s worker settings.

  1. Check the working directory and Python path. A command launched from the project’s parent directory may need a fully qualified package path. A service launched from another directory may not see your source tree unless the package is installed or the correct path is configured.
  2. Look for name collisions. A file named flask.py can shadow the Flask package. Files or directories named like your application package can likewise cause Python to import the wrong module.
  3. Inspect imports that run during startup. A circular import can leave a module “partially initialized.” Move route or blueprint imports until after the Flask object exists, or switch to an application-factory layout.

Match the WSGI target to your application pattern

Application shape Example export Correct target When to use it
Direct instance in a module myapp.py contains app = Flask(__name__) myapp:app Small applications or code that creates one global instance.
Direct instance in a package myapp/__init__.py contains app = Flask(__name__) myapp:app A package layout that still exposes one global instance.
Application factory myapp/__init__.py defines create_app() myapp:create_app() Multiple configurations, tests, reusable extensions, or larger projects.
Explicit WSGI shim wsgi.py assigns application = create_app() wsgi:application Platforms or teams that prefer a conventional, unambiguous entry module.

The filename does not determine the exported object. A file called wsgi.py can expose application, app, or something else; the target must name the variable that really exists.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix a direct Flask instance

Minimal module

Put the instance at module level so the WSGI server can import it without executing a development server:

from flask import Flask

app = Flask(__name__)

@app.get('/')
def index():
    return {'status': 'ok'}

if __name__ == '__main__':
    app.run(debug=True)

For a file named myapp.py, start it with:

gunicorn myapp:app

For local Flask development, the equivalent is:

flask --app myapp run

Do not put the app = Flask(__name__) assignment inside the if __name__ == '__main__' block. A WSGI server imports the module, so that block is not executed during import and no app would be exported.

Common direct-instance mismatches

  • If the variable is named application, use gunicorn myapp:application, not myapp:app.
  • If the file is inside a package, include the package path: gunicorn myapp.server:app, not merely gunicorn server:app when the process starts outside that package directory.
  • If the instance is created by a function, it is not a direct-instance target. Use the factory syntax described below.
  • If importing the module starts a server, opens a socket, or performs other one-time work, move that code behind the __main__ guard or into controlled startup code.

Fix an application-factory target

Factory implementation

An application factory returns a newly configured Flask instance. A typical package looks like this:

myapp/
    __init__.py
    views.py
# myapp/__init__.py
from flask import Flask

def create_app():
    app = Flask(__name__)
    app.config.from_mapping(
        SECRET_KEY='change-this-in-production'
    )

    from .views import bp
    app.register_blueprint(bp)
    return app
# myapp/views.py
from flask import Blueprint

bp = Blueprint('main', __name__)

@bp.get('/')
def index():
    return {'status': 'ok'}

The production target must call the factory:

gunicorn 'myapp:create_app()'

The Flask command-line interface accepts the same form:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
flask --app 'myapp:create_app()' run

Quoting the target is useful in shells that treat parentheses specially. The parentheses are significant: myapp:create_app refers to the function object, while myapp:create_app() tells the loader to call it and use the returned Flask application.

Why the blueprint import is delayed

The factory creates app before importing .views. That order prevents a route module from importing the package while the package is still creating itself. If views.py imports app from myapp at module import time, Python can encounter a partially initialized package and report that it cannot import the name.

For larger projects, extensions can be created without an application and initialized inside the factory:

# extensions.py
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
# myapp/__init__.py
from flask import Flask
from .extensions import db

def create_app():
    app = Flask(__name__)
    app.config.from_object('myapp.config')
    db.init_app(app)
    return app

This pattern lets tests create separate configured applications and reduces pressure to import a global app instance into every module.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use an explicit wsgi.py shim when deployment expects one

A shim gives the process manager a stable module and a plainly named callable:

# wsgi.py
from myapp import create_app

application = create_app()

Point the server at the name you assigned:

gunicorn wsgi:application

If you instead write app = create_app(), the target is wsgi:app. Do not assume that a platform’s default target will discover your preferred variable. Check its entry-point setting and change either the setting or the exported name so they agree.

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

A shim is also useful when the package needs arguments, environment setup, or imports that you do not want to place in the package’s public namespace. Keep it deterministic: importing wsgi.py should finish application setup and expose the callable without launching a development server.

Break circular imports and “partially initialized module” errors

The failure pattern

A common cycle looks like this:

# myapp/__init__.py
from flask import Flask
from .routes import bp

app = Flask(__name__)
app.register_blueprint(bp)
# myapp/routes.py
from myapp import app
from flask import Blueprint

bp = Blueprint('main', __name__)

Importing myapp starts executing __init__.py, which imports routes.py. The route module then asks for app before the assignment has executed. Python sees a real package, but it is only partially initialized, so the requested name is unavailable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Correct the order

Create the application first, then import and register routes:

from flask import Flask

def create_app():
    app = Flask(__name__)
    from .routes import bp
    app.register_blueprint(bp)
    return app

When using a direct global instance, defining app before importing modules that depend on it can remove a simple cycle, but the factory pattern is usually safer as the project grows.

Use current_app inside an application context

Code that needs configuration or services at request time should often use Flask’s context-local proxy rather than importing the global instance:

from flask import current_app

def configured_value():
    return current_app.config['FEATURE_FLAG']

This function must run during a request, CLI command, or an explicit application context. Calling it in a plain script without a context produces a different “working outside of application context” error. For startup code that must run before requests, perform it inside the factory after configuration is loaded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Check imports in both directions

  • Route modules should not import a global app merely to register a route.
  • Configuration modules should not import route modules.
  • Shared helpers should depend on interfaces or context proxies, not on the module that creates the app.
  • Blueprint registration should happen after the Flask object exists.

Understand Flask CLI discovery

Flask’s CLI accepts a dotted module path and, optionally, a variable or factory. Examples include flask --app myapp run, flask --app myapp:application run, and flask --app 'myapp:create_app()' run. When --app is omitted, Flask can automatically look for modules such as app or wsgi and documented names such as app, application, create_app, or make_app.

Automatic discovery is convenient for development but can conceal an incorrect production target. Make the module and exported object explicit in deployment configuration. Also avoid naming your own file flask.py; that name can cause an import of your file when code intends to import the Flask package.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify the process manager’s environment

Working directory

Relative imports and package discovery depend on where the process starts. Run the command from the project directory first:

cd /path/to/project
python -c "import myapp; print(myapp.__file__)"
gunicorn myapp:app

The printed path should be the file you expect, not a second checkout, an old installed copy, or a same-named module elsewhere on the path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Virtual environment and dependencies

Use the same Python environment for the diagnostic import and the production process. A shell may find Flask in one virtual environment while a service manager launches another interpreter. Check the executable used by the process configuration and run:

python -c "import sys, flask; print(sys.executable); print(flask.__file__)"

If your package is not installed, ensure the service’s working directory or Python path includes the project. A fully qualified target such as company_project.myapp:app is preferable to relying on an accidental current-directory import.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Environment variables and startup configuration

A module may create app only after reading a required environment variable. Missing configuration can therefore surface as an import error even though the target is correct. Set required variables in the service environment, then repeat the plain Python import test. Do not hide configuration failures with a broad try/except ImportError; that can turn the original, useful traceback into a misleading missing-name message.

Keep development startup separate from WSGI import

Use the development server only under a main guard:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
if __name__ == '__main__':
    app.run(debug=True)

When Gunicorn or another WSGI server imports the module, the guarded block is skipped. The server then owns sockets, workers, reloading, and request handling. Starting app.run() during import can block the loader, create duplicate processes, or make a deployment appear to hang rather than report the real exported object.

Complete configuration, extension initialization, and route registration before the first request. Flask’s lifecycle guidance requires setup to finish before a worker begins serving traffic; changing routes or configuration after requests have started can produce inconsistent workers.

Read the error by symptom

Symptom Likely cause Correction
cannot import name 'app' from 'myapp' The target asks for app, but the module exports another name or has not reached the assignment. Rename the export or change the target to the actual variable; then inspect earlier traceback lines.
cannot import name 'app' from partially initialized module Circular import during package startup. Create the Flask object before importing routes, delay blueprint imports, and use current_app where an application context is available.
No module named myapp Wrong working directory, package path, interpreter, or installation. Run from the project root, use the full dotted path, or install the package in the active environment.
The import works in a shell but not under the service Different user, virtual environment, current directory, or environment variables. Compare the service’s executable, working directory, Python path, and environment with the successful shell test.
The server starts but serves no routes Blueprints were never registered, or a factory was passed without being called. Register blueprints in the factory and use module:create_app(), not merely module:create_app.
Import launches the development server or hangs app.run() executes at module import time. Put it under if __name__ == '__main__': and let the WSGI server manage production startup.

Choose between a direct instance, factory, and shim

Decision factor Direct instance Factory WSGI shim
Small single-configuration app Shortest setup; module:app is clear. More structure than necessary unless tests already need it. Optional extra file.
Multiple configurations or test apps Global state can leak between tests. Strong fit; each call can create an isolated app. Can expose one selected factory result to a platform.
Circular-import risk Increases as modules import the global instance. Lower when routes are imported after creation. Depends on how the shim and package imports are arranged.
Deployment clarity Requires every operator to know the module and variable. Explicit callable syntax documents the lifecycle. One conventional entry point, useful when a host expects wsgi.py.

There is no need to convert a small, working direct-instance application solely to resolve this error. First make its target accurate. Adopt a factory when configuration isolation, testing, extension initialization, or import boundaries justify it.

Production deployment checklist

  • Confirm the application is a WSGI callable, not a coroutine, route function, or development-server command.
  • Confirm the target’s module path and exported name match exactly.
  • For factories, include parentheses in the target and quote the command when the shell requires it.
  • Run a plain Python import using the same interpreter, user, working directory, and environment as the service.
  • Ensure the package is installed or discoverable on the service’s Python path.
  • Remove files named flask.py or other modules that shadow dependencies.
  • Register blueprints after app creation and eliminate imports that reach back into a partially initialized package.
  • Use current_app for context-dependent code instead of importing the global app everywhere.
  • Keep app.run() behind the main guard and use a dedicated WSGI server or hosting platform for production.
  • Make all configuration and route setup complete before workers begin handling requests.

Quick reference commands

Direct instance in myapp.py

gunicorn myapp:app
flask --app myapp run

Factory in myapp/__init__.py

gunicorn 'myapp:create_app()'
flask --app 'myapp:create_app()' run

Explicit shim

# wsgi.py exports application
 gunicorn wsgi:application

Remove the leading space before gunicorn if you copy the last command; it is shown only as ordinary code text here. The decisive check in every case is the same: import the module, verify the exported name, and fix the first initialization failure in the traceback.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.