3

I'm getting an error:

MacBook-Pro:microblog_3 olehdubno$ python db_create.py 
Traceback (most recent call last):
  File "db_create.py", line 5, in <module>
    from app import db
  File "/Users/olehdubno/Desktop/microblog_3/app/__init__.py", line 2, in <module>
    from flask.ext.sqlalchemy import SQLAlchemy
  File "/usr/local/lib/python2.7/site-packages/flask/exthook.py", line 81, in load_module
    reraise(exc_type, exc_value, tb.tb_next)
  File "/usr/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 24, in <module>
    from sqlalchemy import orm, event
ImportError: cannot import name event   

I'm working on Part IV: Database: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database.

My github code: https://github.com/odubno/microblog.

Anything I do, I cannot get event imported. Simply trying from sqlalchemy import event doesn't work either.

Flask==0.10.1
Flask-Restless==0.17.0
Flask-SQLAlchemy==2.0
Flask-WTF==0.11
GraphLab-Create==1.1
Jinja2==2.7.3
MarkupSafe==0.23
Pillow==2.7.0
SQLAlchemy==0.6.8
Tempita==0.5.2
WTForms==2.0.2
Werkzeug==0.10.1
argparse==1.2.1
backports.ssl-match-hostname==3.4.0.2
blaze==0.6.0
boto==2.33.0
daemonize==2.3.1
decorator==3.4.0
folium==0.1.2
geopy==1.4.0
george==0.2.1
ggplot==0.6.5
itsdangerous==0.24
librato-metrics==0.4.9
mimerender==0.5.5
mixpanel-py==3.1.1
nltk==3.0.0
nose==1.3.4
numpy==1.8.2
oauthlib==0.7.2
pandas==0.14.1
patsy==0.3.0
prettytable==0.7.2
psycopg2==2.5.4
pyparsing==2.0.3
pyshp==1.2.1
python-dateutil==2.4.1
python-mimeparse==0.1.4
pytz==2014.7
requests==2.3.0
requests-oauthlib==0.4.2
scikit-learn==0.15.1
six==1.9.0
sqlalchemy-migrate==0.7.2
suds==0.4
sympy==0.7.5
textblob==0.9.0
tornado==3.2.1
twitter==1.15.0
vboxapi==1.0
virtualenv==1.11.6
wsgiref==0.1.2
xlrd==0.9.3
xlwt==0.7.5

2 Answers 2

4

Events were added to SQLAlchemy in version 0.7. You are using version 0.6.8. Upgrading will fix your ImportError.

pip install -U sqlalchemy

Version 0.7 was released several years ago. 0.9.9 is the most recent (at the time of this answer). Unless you have a specific need for 0.6, upgrading should be well worth it.

Sign up to request clarification or add additional context in comments.

Comments

0

I tried pip install -U sqlalchemy and weirdly it still didn't resolve the issue.

What did work and I forgot to use was the virtualenv.

Once I activated my virtualenv in terminal using:

$ virtualenv venv --distribute
New python executable in venv/bin/python
Installing distribute.........done.
Installing pip................done.
$ source venv/bin/activate
(venv)$ python

I followed up by:

pip install sqlalchemy

Following the tutorial, I installed the rest of the extensions in virtualenv and everything works now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.