pythonflaskflask-migrate

ModuleNotFoundError: No module named 'flask_migrate'


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?


Solution

  • 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).