Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask run Error: While importing 'project', an ImportError was raised

I have project directory named Project, and project directory includes python files and html files et al., and want to deploy in the AWS ec2 ubuntu sever.when I run in the local is ok.

when run "flask run" under the Project directory, there is error in the ubuntu terminal.

flask run
 * Serving Flask app 'project' (lazy loading)
 * Environment: development
 * Debug mode: on
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: While importing 'project', an ImportError was raised

I have set a .flaskenv file as following:

FLASK_APP=project
FLASK_ENV=development 
like image 606
tktktk0711 Avatar asked Oct 12 '25 03:10

tktktk0711


2 Answers

In my case, there was an error in importing a specific library on FLASK_APP file. Running the command python app.py as jluu suggested will help you to know exactly when the ImportError happens.

like image 99
Raghad Avatar answered Oct 14 '25 19:10

Raghad


Did you installed your dependencies on your remote server? If yes, try installing your app as a module.

Given a the following directory structure:

/yourapplication
/yourApplicationMainFolder
    __init__.py
    /static
        style.css
    /templates
        layout.html
        index.html
        login.html
        ...

Create a setup.py file on /yourapplication/setup.py with:

from setuptools import setup

setup(
    name='yourApplicationMainFolder',
    packages=['yourApplicationMainFolder'],
    include_package_data=True,
    install_requires=[
        'flask',
],)

Install with pip:

pip install -e .

If that did not work, comment out all your imports in the main script and inspect one by one to see which one is the problem.

like image 32
Kaio Delphino Avatar answered Oct 14 '25 21:10

Kaio Delphino