ImportError: No module named flask.ext.restless

user2657669 picture user2657669 · Jun 1, 2014 · Viewed 9.8k times · Source

I'm trying to make Restful endpoints for a sqlalchemy database. But for some reason it can't find the Flask Restless extension.

When I run the file I get this error:

Traceback (most recent call last):
  File "./rest1.py", line 7, in <module>
    import flask.ext.restless
  File "/home/ian/git_dev/flask_rest/test2/flask/local/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.restless

I have Flask, Flask-Restless and SQLalchemy installed but it still won't work.

Django==1.6.5
Flask==0.10.1
Flask-Restless==0.13.1
Jinja2==2.7.2
MarkupSafe==0.23
PAM==0.4.2
Pillow==2.3.0
SQLAlchemy==0.9.4

This is my code:

#!flask/bin/python
#!/usr/bin/python
# -*- mode: python -*-

from flask import Flask
from sqlalchemy import Column, Date, DateTime, Float, Integer, Unicode
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
import flask.ext.restless

app = Flask(__name__)
engine = create_engine('sqlite:////tmp/testdb.sqlite', convert_unicode=True)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
mysession = scoped_session(Session)

Base = declarative_base()
Base.metadata.bind = engine

class Test_Table(Base):
    __tablename__ = 'plot'
    id = Column(DateTime, primary_key=True)
    value = Column(Integer)
    type = Column(Unicode)
    max = Column(Integer)
    min = Column(Integer)


Base.metadata.create_all()

manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)

manager.create_api(Test_Table, methods=['GET', 'POST', 'PUT' 'DELETE'])

app.run()

I've tried Flask-Restful as well, both within and outside virtual environments. But I still end up with the same result.

Answer

Padraic Cunningham picture Padraic Cunningham · Jun 1, 2014

You can try reinstalling pip install --upgrade --force-reinstall flask_restless

If that does not work:

install flask_restless 0.14-dev from github.

git clone https://github.com/jfinkels/flask-restless

 cd flask-restless
 pip install -r requirements-doc.txt

Use import flask_restless

   flask_restless.__version__
   '0.13.1'

to make sure python is seeing the correct version of flask_restless.

You also seem to have a "flask" dir in your path:

'/home/ian/git_dev/flask_rest/test2/flask/local/lib/python2.7/site-packages/flask/exthook.py'

that may be conflicting with your imports.