After successful installation of cjklib and CEDICT, when I use it, it throw errors, why?
Question: This is my first post here.

I have been reading posts here since I started learning python and it has been
nothing but a great help to my learning process. So, just want to say A BIG
THANK YOU to you all before my question!

**Question:**

I installed the cjklib package successfully. Then, I installed the CEDICT
dictionary successfully as well. But when I try to use CEDICT, it always
throws errors like this:

    
    
    >>> d = CEDICT()
    ......
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 335, in do_execute
    sqlalchemy.exc.OperationalError: (OperationalError) unknown database "cedict_0" 'PRAGMA "cedict_0".table_info("CEDICT")' ()
    >>> 
    

**To reproduce the problem:**

_Install the cjklib package:_

Download the cjklib-0.3.tar.gz, extract it and update the files in directory
Cjklib-0.3/cjklib/build/*.py (specifically, builder.py and **init**.py):

Update "from sqlalchemy.exceptions" to "from sqlalchemy.exc"

    
    
    $cd djklib-0.3/cjklib/build/
    $sudo python setup.py install
    $sudo installcjkdict CEDICT
    $python
    Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from cjklib.dictionary import CEDICT
    >>> d = CEDICT()
    

The error occurs, in details, as below:

    
    
    >>> d = CEDICT()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dictionary/__init__.py", line 605, in __init__
        super(CEDICT, self).__init__(**options)
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dictionary/__init__.py", line 532, in __init__
        super(EDICTStyleEnhancedReadingDictionary, self).__init__(**options)
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dictionary/__init__.py", line 269, in __init__
        if not self.available(self.db):
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dictionary/__init__.py", line 276, in available
        and dbConnectInst.hasTable(cls.DICTIONARY_TABLE))
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dbconnector.py", line 444, in hasTable
        schema = self._findTable(tableName)
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dbconnector.py", line 429, in _findTable
        if hasTable(tableName, schema=schema):
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 2525, in has_table
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 2412, in run_callable
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1959, in run_callable
      File "build/bdist.linux-x86_64/egg/sqlalchemy/dialects/sqlite/base.py", line 567, in has_table
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1450, in execute
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1627, in _execute_text
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1697, in _execute_context
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1690, in _execute_context
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 335, in do_execute
    sqlalchemy.exc.OperationalError: (OperationalError) unknown database "cedict_0" 'PRAGMA "cedict_0".table_info("CEDICT")' ()
    >>>
    

**Tryouts:** I tried some solutions myself, like:

As the error indicated, it can't find the table in the sqlite database file,
so I edited the cjklib.conf file by adding following the line to tell it that
the table is right here:

    
    
    url = sqlite:////usr/local/share/cjklib/cedict.db
    

Then, it found the table CEDICT and stopped throwing the errors. But
unfortunately, it started throwing another kind of error when I ran the code
below:

    
    
    >>> from cjklib import characterlookup
    >>> cjk = characterlookup.CharacterLookup('T')
    

Error:

    
    
    >>> cjk = characterlookup.CharacterLookup('T')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/cjklib/characterlookup.py", line 118, in __init__
        self.hasComponentLookup = self.db.hasTable('ComponentLookup')
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dbconnector.py", line 444, in hasTable
        schema = self._findTable(tableName)
      File "/usr/local/lib/python2.7/dist-packages/cjklib/dbconnector.py", line 429, in _findTable
        if hasTable(tableName, schema=schema):
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 2525, in has_table
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 2412, in run_callable
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1959, in run_callable
      File "build/bdist.linux-x86_64/egg/sqlalchemy/dialects/sqlite/base.py", line 567, in has_table
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1450, in execute
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1627, in _execute_text
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1697, in _execute_context
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1690, in _execute_context
      File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 335, in do_execute
    sqlalchemy.exc.OperationalError: (OperationalError) unknown database "cjklib_0" 'PRAGMA "cjklib_0".table_info("ComponentLookup")' ()
    

If i delete the line I added, it will work as expected again.

**Solutions:**

How can I make it read both cedict.db and cjklib.db at the same time? I am
guessing, only then, it might work for both cases without throwing any errors.

Did anyone encounter a similar situation? And how did you solve it? Or, do you
have anything else to try out in mind? Just shed some lights please!

Thanks in advance!


Answer: (1) Your method to make CEDICT work is **not complete**. Although "d =
CEDICT()" doesn't raise any error, you will meet an error when you a
dictionary function, such as "d.getFor(u'朋友')". You should add an item in the
config file:

    
    
    attach = sqlite:////usr/local/share/cjklib/cjklib.db
    

But, this method still gives a "characterlookup" error (as you mentioned).

(2) Real solution: create "dbconnection" explicitly for the dictionary.

    
    
    >>> from cjklib.dictionary import CEDICT
    >>> from cjklib.dbconnector import getDBConnector
    >>> db = getDBConnector({'sqlalchemy.url': 'sqlite://', 'attach': ['cjklib']})
    >>> d=CEDICT(dbConnectInst=db)
    >>> it=d.getFor(u'朋友')
    

**EDIT:**

Keep cjklib.conf with default configuration.

