Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask - ImportError: No module named migrate.versioning

I'm working through a flask tutorial and am trying to run a script that creates a database instead of doing it through the command line. It uses the SQLAlchemy-migrate package, but when I try to run the script, it gives an ImportError.

This is the terminal output:

Sean:app seanpatterson$ python ./db_create.py 
Traceback (most recent call last):
  File "./db_create.py", line 2, in <module>
    from migrate.versioning import api
ImportError: No module named migrate.versioning

This is the db_create.py script:

#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,     api.version(SQLALCHEMY_MIGRATE_REPO))

This is the config file it references:

#!/usr/bin/env python
import os
basedir = os.path.abspath(os.path.dirname(__file__))

SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')

This application is being run with a virtual environment. This are the module that relates to it that I have installed in the environment:

sqlalchemy_migrate-0.7.2-py2.7.egg-info

Any help appreciated

like image 650
Takeshi Patterson Avatar asked Feb 08 '14 13:02

Takeshi Patterson


5 Answers

pip install sqlalchemy==0.7.9 

and

pip install sqlalchemy-migrate==0.7.2 

and

optionally this flask-whooshalchemy==0.55a should solve the problem

like image 199
Transformer Avatar answered Oct 05 '22 08:10

Transformer


ImportError: No module named migrate.versioning probably means the module is not installed. Make sure it has been installed in the correct virtual environment, it is activated (you ran the activate script in that environment) and the selected Python binary is actually making use of that environment (i.e. you are using Python2 and not Python3).

like image 20
BoppreH Avatar answered Oct 05 '22 07:10

BoppreH


As said by @BoppreH earlier

ImportError: No module named migrate.versioning

means that the module named 'migrate' is not installed in your virtual environment or your system. First make sure that you are using the proper environment and that it is activated using the activate script.

I had the same problem and had the correct environment set up. But still the error was not solved.

What worked for me was installing the sqlalchemy-migrate package from pip. After activating my environment, I ran the following code to install it :

pip install sqlalchemy-migrate
like image 27
97amarnathk Avatar answered Oct 05 '22 07:10

97amarnathk


flask/bin/pip install flask-sqlalchemy without defining the version worked fine for me.

like image 39
Sudeep Acharya Avatar answered Oct 05 '22 09:10

Sudeep Acharya


run :

   easy_install Flask-SQLAlchemy

to install Flask-SQLAlchemy

   sudo pip install flask-migrate

to install flask-migrate

like image 31
li bing zhao Avatar answered Oct 05 '22 09:10

li bing zhao