简体   繁体   English

pyenchant在Mac OS X上找不到字典文件

[英]pyenchant can't find dictionary file on Mac OS X

I'm having trouble installing pyenchant on a MacbookPro running Lion. 我在运行Lion的MacbookPro上安装pyenchant时遇到了麻烦。 I've used homebrew and pip to install enchant and pyenchant 我用自制软件和点子来安装附魔和诡计

homebrew install enchant 自制软件安装附魔

pip install pyenchant pip install pyenchant

I've also downloaded an English dictionary to the following folder: 我还下载了一个英文字典到以下文件夹:

/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/share/enchant/myspell /usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/share/enchant/myspell

-rw-r--r--  1 mycomputer  admin      75 Jun  6 13:34 README.txt
-rw-rw-rw-@ 1 mycomputer  staff    1017 May  4  2007 README_en_US.txt
drwx------@ 2 mycomputer  staff      68 Jun  6 13:38 en_US
-rw-rw-rw-@ 1 mycomputer  staff    3045 May  4  2007 en_US.aff
-rw-rw-rw-@ 1 mycomputer  staff  696131 May  4  2007 en_US.dic

However, when I try to use enchant, I get the following error. 但是,当我尝试使用附魔时,我收到以下错误。

>>> import enchant
>>> d = enchant.Dict('en_US')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/__init__.py", line 502, in __init__
    self._switch_this(broker._request_dict_data(tag),broker)
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/__init__.py", line 264, in _request_dict_data
    self._raise_error(eStr % (tag,),DictNotFoundError)
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/__init__.py", line 218, in _raise_error
    raise eclass(default)
enchant.errors.DictNotFoundError: Dictionary for language 'en_US' could not be found

I'm guessing I don't have the dictionary files installed in the correct folder, but I don't know where else to install them. 我猜我没有在正确的文件夹中安装字典文件,但我不知道在哪里安装它们。

Thanks. 谢谢。

Enchant is 'lazy' and need backend support from aspell. 附魔是'懒惰',需要来自aspell的后端支持。

So, what you need to do is: 那么,你需要做的是:

brew remove aspell
brew install aspell --lang=en

Then en dicts will be installed and so no need to download additional dicts. 然后将安装en dicts,因此无需下载其他dicts。

I also was able to solve by explicitly setting the parameter for the dictionary path. 我还能够通过显式设置字典路径的参数来解决。 Don't have brew installed - am using mac ports. 没有安装brew - 我正在使用mac端口。 Had to manually download the oxt file from apache open office and extract the files from it (after renaming .oxt to .zip . Where are these default path values stored? 不得不从apache open office手动下载oxt文件并从中提取文件(在将.oxt重命名为.zip 。这些默认路径值存储在哪里?

Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)   
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>>  
>>> import enchant  
>>> d = enchant.Dict("en_US")  
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>  
  File "/Library/Python/2.7/site-packages/pyenchant-1.6.5-py2.7.egg/enchant/__init__.py", line 502,   in __init__  
    self._switch_this(broker._request_dict_data(tag),broker)   
  File "/Library/Python/2.7/site-packages/pyenchant-1.6.5-py2.7.egg/enchant/__init__.py", line 264, 
  in _request_dict_data  
    self._raise_error(eStr % (tag,),DictNotFoundError)  
  File "/Library/Python/2.7/site-packages/pyenchant-1.6.5-py2.7.egg/enchant/__init__.py", line 218,   in _raise_error  
    raise eclass(default)  
enchant.errors.DictNotFoundError: Dictionary for language 'en_US' could not be found  

Now I apply the fix using my filesystem specifics: 现在我使用我的文件系统细节来应用修复:

>>> enchant.set_param("enchant.myspell.dictionary.path","/Library/Python/2.7/site-packages/pyenchant-1.6.5-py2.7.egg/enchant/share/enchant/myspell")  
>>> d=enchant.Dict("en_US")
>>> d.check("enchant")  
True  
>>>   

Seeing is believing - again - where is the default version of this path stored (I am a newby to Python and Eggs - coming from Java and Jars) Seeing相信 - 再次 - 存储此路径的默认版本(我是Python和Eggs的新手 - 来自Java和Jars)

I was able to solve this using the command: 我能够使用命令解决这个问题:

enchant.set_param("enchant.myspell.dictionary.path", "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/share/enchant/myspell") enchant.set_param(“enchant.myspell.dictionary.path”,“/ usr / local / Cellar / python / 2.72 / lib / python2.7 / site-package / enchant / share / enchant / myspers”)

Other people who had installed enchant using ports did not have this issue. 其他使用端口安装附魔的人没有这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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