ModuleNotFoundError: No module named 'flask_migrate'

12,542

Solution 1

From the CLI you need to run your script as follows:

python flasky.py

When you just run flasky.py Windows opens the script with the executable registered to handle the .py. extension on your system, which is your system-wide Python interpreter (i.e. not the interpreter associated with your virtual environment).

Solution 2

Try reinstalling the pip install Flask-Migrate. This worked for me

Solution 3

sudo apt-get install python3-flask-migrate -y 
Share:
12,542

Related videos on Youtube

maorui2k
Author by

maorui2k

Updated on June 04, 2022

Comments

  • maorui2k
    maorui2k over 1 year

    I'm new to python+flask, and wanted to use flask to create a website. The IDE is Visual studio 2017, and I could run the program successfully with flasky.py as startup file. But in CLI, I constantly got this error.

    (sms) C:\Document\Workspace\smsserver\smsserver>flasky.py
    Traceback (most recent call last):
      File "C:\Document\Workspace\smsserver\smsserver\flasky.py", line 3, in <module>
        from flask_migrate import Migrate
    ModuleNotFoundError: No module named 'flask_migrate'
    

    The codes are:

    import os
    from os import environ
    from flask_migrate import Migrate
    from app import create_app, db
    import app.models
    
    app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    migrate = Migrate(app, db)
    ....
    

    Here are modules installed in the venv.

    (sms) C:\Document\Workspace\smsserver\smsserver>pip freeze
    alembic==1.0.7
    ...
    Flask==1.0.2
    Flask-Bootstrap==3.3.7.1
    Flask-Mail==0.9.1
    Flask-Migrate==2.3.1
    Flask-SQLAlchemy==2.3.2
    ....
    SQLAlchemy==1.2.17
    sqlalchemy-migrate==0.12.0
    sqlparse==0.2.4
    ....
    

    Is there anything I missed? Or any module confliction?

  • maorui2k
    maorui2k over 4 years
    It works. Thank you! I misunderstood the virtual env and Python interpreter.