0

I have been following a tutorial from 'Django by example' that introduces Solr and Haystack and run into a problem. I have made the necessary changes to INSTALLED_APPS in settings.py and also added the following:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backends.SolrEngine',
        'URL': 'http://127.0.0.1:8938/solr/blog'
    }, 
}

then I run

python manage.py build_solr_schema

and I get this error

ImportError: No module named 'haystack.backends.solr_backends'

this is my search_indexes.py file

   from haystack import indexes
   from .models import Post
   class PostIndex(indexes.SearchIndex, indexes.Indexable):
   text = indexes.CharField(document=True, use_template=True)
   publish = indexes.DateTimeField(model_attr='publish')
   def get_model(self):
       return Post
   def index_queryset(self, using=None):
       return self.get_model().published.all()

when I run django shell Im able to import haystack just fine but when I run the following:

from haystack.query import SearchQuerySet
sqs = SearchQuerySet().all()
sqs.count()

I get the exact same error right after entering the 2nd line.

I have tried restarting Solr, still doesn't work.

I have Solr working fine locally and have created a new core within the admin and have all the files setup here and have all the required files copied over from the example folder that comes with the install:

/usr/local/opt/solr/server/solr/blog/conf

what am I missing here? thanks

EDIT: Id like to add that I have installed django-haystack and pysolr with a venv but both show up if I do pip freeze. Solr was installed via Homebrew.

easy_c0mpany80
  • 327
  • 1
  • 7
  • 18

2 Answers2

1

This problem usually occurs when first adding Haystack to your project.

1.Are you using the haystack directory within your django-haystack checkout/install?

2.Is the haystack directory on your PYTHONPATH? Alternatively, is haystack symlinked into your project?

3.Start a Django shell (./manage.py shell) and try import haystack. You may receive a different, more descriptive error message.

4.Double-check to ensure you have no circular imports. (i.e. module A tries importing from module B which is trying to import from module A.)

Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47
  • #1 - Im not sure, Im in my venv, I installed django-haystack within the venv and it shows up with pip freeze #2 I think so? This is my PATH /Users/david/Documents/projects/django/mysite/venv/bin:/Applications/Postgres.app/Contents/Versions/9.4/bin/:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin I installed with pip so doesn't it take care of that? #3 I tried that already and can import fine #4 none that I can see – easy_c0mpany80 Jun 14 '16 at 14:43
  • can you check this http://stackoverflow.com/questions/14695278/python-packages-not-installing-in-virtualenv-using-pip – Abhijit Bashetti Jun 14 '16 at 14:46
  • thanks but how does that link address my problem? That person was corrected for using sudo with their pip installs which I have not been doing, also django-haystack shows up just fine when I do pip freeze, I can import it in django shell and when I check its install location with pip show I can see that its installed in the correct location within my venv. I appreciate the contribution but I think Im still stuck in the same place :( – easy_c0mpany80 Jun 15 '16 at 02:28
0

so I eventually found that it was just a typo error here

'ENGINE': 'haystack.backends.solr_backends.SolrEngine',

this should be 'solr_backend' not plural :|

easy_c0mpany80
  • 327
  • 1
  • 7
  • 18