No module named constants
Asked Answered
S

2

7

I want to do sample application with Tastypie framework.

I added Tastypie to Installed app and modified urls.py as required, adding from tastypie.api import Api. But when I open http://localhost:8000/api/v1/?format=json, I get the following exception:

Exception Value: No module named constants

When I run:

pip install constants

everything looks ok.

Python 2.6 (and try on 2.7)
Django 1.4
Tastypie 0.10.0
Staten answered 12/8, 2013 at 15:43 Comment(4)
This should helpEnfeeble
Usually installing a package won't help when you're missing a module, especially one named constants, add your entire stacktrace and urls.Inconsumable
from tastypie.api import Api from api.resources import ApiData v1_api = Api(api_name='v1') v1_api.register(ApiData()) urlpatterns = patterns('', url(r'^api/', include(v1_api.urls)), )Staten
Just update django to 1.5. Thanks!Staten
I
7

the problem is in the resources.py file for tastypie. It has the following line:

from django.db.models.constants import LOOKUP_SEP

That import will only work on 1.5+. For django < 1.5, it should be:

from django.db.models.sql.constants import LOOKUP_SEP

Upgrading to 1.5 will definitely fix it, but for those who can't, temporarily downgrade tastypie or do that fix yourself.

Illomened answered 26/9, 2013 at 20:42 Comment(0)
F
0

Not really specific to Tastypie or Python 2.7, but I've seen the same error for nrfutil on Python 3.9.

The solution to this was downgrading Python to 3.8, where everything worked like a charm.

Furmenty answered 12/8, 2013 at 15:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.