简体   繁体   中英

Using Django and PyEnchant: Getting MemoryError on shared hosting, but not locally

I'm a beginner level user of Django and Python right now, and so far anything I do locally has immediately worked on my hosting once uploaded. My hosting is provided by Hostmonster.

However, I've just installed PyEnchant. All I use it for is basic spell checking and suggesting new words. Also, 'string' is always a string of words separated by '+'.

from enchant import Dict

def spellcheck(string):
    spellcheck = Dict("en-GB")

    suggestedword = []

    for word in string.split('+'):
        if len(word) > 2 and not spellcheck.check(word):
           suggestedword.append(spellcheck.suggest(word)[0])
    else:
        suggestedword.append(word)

return suggestedword

Locally, using the Django dev server, all works fine. On my host I get:

Django Version: 1.4

Exception Type: MemoryError

Exception Location: /home/user/python/lib/python2.7/ctypes/__init__.py in _reset_cache, line 279

It seems to be throwing the error a few steps after 'from enchant import Dict'.

I'm guessing the dictionary is too large to store in temporary memory?

Any idea how to get around this? Please go easy on me if I'm either asking something very stupid, or in a very stupid way :).

If I'm leaving out any vital data, it's because I don't know it's important, so feel free to tell me what other information would help solve this (if it can be solved on a shared host).

Thanks in advance for any help!

EDIT1:

Using SSH, I can import and use PyEnchant:

>>> import enchant
>>> spellcheck = enchant.Dict("en-GB")
>>> spellcheck.suggest('nmae')
['name', 'mane']

Which makes me even more confused, as I have had no luck avoiding 'MemoryError' when I use it as above in my question.

EDIT2:

Still not able to figure this out. If I do 'import enchant' in any module, it seems to cause the MemoryError, yet I am able to use 'import enchant' via remote shell and the python interpreter.

EDIT3:

Still, after a few days of googling and trying things out, I can't get this MemoryError to go away. Has anyone seen this before with 'PyEnchant'? I'm thinking my host is perhaps not giving enough ram to load the PyEnchant import? Is there any way to change how memory is used by a module?

I have just had the same problem after moving my Django installation. The problem was httpd (Apache) access to the database. In my case it was Selinux but I assume that general UNIX type file permissions would cause a similar problem. In this instance it worked fine on the Django server but not on my local Apache when trying out a viable production setup.

  • Does your host use Linux?
  • Could you run Apache to help determine the problem?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM