rcamba / kanji_to_romaji

Tries to translate Kanji to Romaji with the help of JMdict
Mozilla Public License 2.0
17 stars 8 forks source link

ModuleNotFoundError: No module named 'kanji_to_romaji_module' #1

Open yudataguy opened 6 years ago

yudataguy commented 6 years ago

What's the likely cause of this error?

from kanji_to_romaji import kanji_to_romaji
Traceback (most recent call last):

  File "<ipython-input-3-6515838f720b>", line 1, in <module>
    from kanji_to_romaji import kanji_to_romaji

  File "/Users/xxxxxx/anaconda3/lib/python3.6/site-packages/kanji_to_romaji/__init__.py", line 1, in <module>
    from kanji_to_romaji_module import convert_hiragana_to_katakana, translate_to_romaji, translate_soukon, \

ModuleNotFoundError: No module named 'kanji_to_romaji_module'
thematrixdev commented 6 years ago

I have got the same error message.

thematrixdev commented 6 years ago

I believe this module is for Python 2 only. Python 3 is not supported.

lorithai commented 5 years ago

You can make this work in python3 without to much change. In the __init__.py of the main folder and the models module folder add a . in front of each of the imports

For the models __init__.py

from .UnicodeRomajiMapping import UnicodeRomajiMapping
from .KanjiBlock import KanjiBlock
from .Particle import Particle

While for the main __init__.py

from .kanji_to_romaji_module import convert_hiragana_to_katakana, translate_to_romaji, translate_soukon, \
    translate_long_vowel, translate_soukon_ch, kanji_to_romaji

When this is done you will still get some errors due to minor differences in how python2 and 3 works. To get this working you need to make some changes in the kanji_to_romaji_module.py

  1. all prints have to have parenthesis added, there are only two that i am aware of. Use ctrl+f to find them.
  2. The decode and the encode part of the kanji_to_romaji function isn't needed in python3 as the default encoding is utf-8 (decode is in the if statement, encode is in the return). Simply remove the if statement, and return the r variable as is.
  3. enforce utf-8 encoding when loading the dictionaries. (load_kana_mappings_dict() and load_kanji_mappings_dict). Just add encoding='utf-8' in the open function. open(os.path.join(JP_MAPPINGS_PATH, f),encoding='utf-8') For some reason the open function defaults to cp1252 encoding and i got some UnicodeDecodeError if i didn't do this.

With these steps taken, i got it to work in python 3. image

I would make a fork or commit, but i am new to git and python development, so not sure how to proceed.

cheers.

onnudilol commented 5 years ago

@lorithai thank you for your contribution. I made a PR implementing the changes that you outlined.

https://github.com/rcamba/kanji_to_romaji/pull/3

ubhatti commented 3 years ago

Hello,

Any progress on the PR from @onnudilol ? I tested it and works fine for me. I would be really great to have it integrated and generate a pip package from it.

thanks in advance.