macos : fix installation to correctly target the installation folder for mecab.py and dictionnaries#11
Conversation
|
I just don't understand why you need to change the value of the |
|
It is worth noting that this PR does not force you to do this setup. It should fall back on the previous behavior. Personally I dont have a problem allowing this in but I am a bit worried about adding complication to the instructions since it may not be necessary. If you can provide some info on what system you're on that might be helpful so we can maybe point out to a more specific range of users that may need this. |
|
Problem with this PR (env part of it) is the fact that it does nothing: Then what's the point to use the env variable if you already have this directory after cloning the repository? |
|
If you want to store dictionary data somewhere else then you should use symbolic link. |
|
Well on my end, each them time a call was made to mecab, it was returning an empty array. After a few hours of debugging, I finally realized it was looking for the dictionnary plugin in the same folder as Which later in the script is looped over to find dictionnaries Thing is, Meaning, it finds no "mecabs", and thus no tokenizing succeed. What have you tested exactly @YukiNagat0 ? Because if you mean looking up words works with mecab enabled, it will indeed work because it is in fact fallbacking to the simple method if no results are coming back from mecab. But in my case, in the /tokenize endpoint, I do take the result of mecab and I was getting empty arrays again and again. (By default, the /tokenize endpoint will never use mecab, but that's part of my next PR to Yomitan to allow tokenizing through mecab, see branch below) Maybe you could check if, in the extension directory, you see the data with the dictionaries? In my case, those get downloaded in the repo folder while the It was pretty difficult to debug because the logs where thrown in the stderr of chrome, so to debug it I had to do print on stderr (stdout won't be logged by chrome output) Cf screenshots. By the way, to make the /tokenize work with mecab, you'd also need this branch : |
|
@YukiNagat0 , if after test you see this issue is not happening in Windows (That the data folder is found correctly), and thus the issue being more about macos handling, I can do changes only to the macos logic by doing this diff instead : diff --git a/install_mecab_for_yomitan.py b/install_mecab_for_yomitan.py
index 05d83af..915e614 100755
--- a/install_mecab_for_yomitan.py
+++ b/install_mecab_for_yomitan.py
@@ -21,7 +21,6 @@ import os
import json
import copy
import zipfile
-import shutil
if sys.version_info[0] == 3:
from urllib.request import urlretrieve
elif sys.version_info[0] == 2:
@@ -241,7 +240,7 @@ def main():
if platform_data['platform'] == 'mac':
script_path = os.path.join(manifest_install_data['path'], 'mecab.py')
try:
- shutil.copy(os.path.join(DIR, 'mecab.py'), script_path)
+ os.symlink(os.path.join(DIR, 'mecab.py'), script_path)
print(f"File copied from {os.path.join(DIR, 'mecab.py')} to {script_path}")
except FileNotFoundError:
print("File not found.")
diff --git a/mecab.py b/mecab.py
index 85c2a5c..bcaf0a7 100755
--- a/mecab.py
+++ b/mecab.py
@@ -34,7 +34,8 @@ elif sys.version_info[0] == 2:
import Queue as queue
from itertools import izip_longest as zip_longest
-DIR = os.path.realpath(os.path.dirname(__file__))
+# First resolve __file__ itself (in case mecab.py is a symlink), then get its directory
+DIR = os.path.dirname(os.path.realpath(__file__)) |
|
Well, I don't have a mac machine, but I am sure that it is mac specific issue.
On windows the scheme is almost identical:
Now, why it doesn't work on macos . yomitan-mecab-installer/install_mecab_for_yomitan.py Lines 240 to 245 in 1b29ff2 So on macos we have broken (half-backed) setup: However, Now the question: how to solve the issue for macos. yomitan-mecab-installer/install_mecab_for_yomitan.py Lines 240 to 251 in 1b29ff2 If macos requires that script needs to be placed in the |
|
So the goal (on macos) is to find a way where we only create the Or (if it is impossible) copy/move everything to Making the |
It does because of this Basically first get the realpath then the dirname, instead of doing the dirname then the realpath. I'm testing it right now and it seems to work fine. I wonder if it's not the simplest solution here since mecab.py just have to know where to look and it gives it the right location. |
|
Well actually putting the right link to the {
"name": "yomitan_mecab",
"description": "MeCab for Yomitan",
"type": "stdio",
"path": "/Users/jschoreels/workspace/yomitan-mecab-installer/mecab.py",
"allowed_origins": [
"chrome-extension://likgccmbimhjbgkjambclfkhldnlhbnn/",
"chrome-extension://glnaenfapkkecknnmginabpmgkenenml/",
"chrome-extension://igbfpblkdooilgjjadkohgmcandjdmnf/"
]
}So I guess we can maybe use this approach to make it consistent across systems ? |
So, the solution is to delete these lines, right? yomitan-mecab-installer/install_mecab_for_yomitan.py Lines 240 to 251 in 1b29ff2 |
|
Well the path generated in the file is incorrent : So I'll quickly start from scratch and remove the copy (the lines you mentionned) and put the right path in that json |
It should be already the right path: |
…json. Copying mecab.py is not needed because of that
62025d7 to
bb2f8ea
Compare
|
The script_path was overridden with one of the lines you removed But thus, simply removing those 12 lines were in fact sufficient. Thanks a lot for the investigation and to have taken time to explain how it was meant to work, next time I'll ping you first I guess :) I've pushed force the new patch I wonder exactly what was the permission issue the previous contributor faced, it seems to work OK here. I thought about maybe he had Google installed as a "global app" of somekind, but then copying mecab.py wouldn't have worked either... |
Kuuuube
left a comment
There was a problem hiding this comment.
Assuming this is all figured out now and good to go. Will wait a bit to merge incase there's any additional comments to be made.
Sure, thanks for the follow up |

By running experiment with Yomitan API, I noticed how changing from mecab or not wasn't changing anything and when checking the code of Yomitan itself, I noticed it should have parsed differently sentence.
After investigation, I realized the mecab integration while being "Successfuly connected" was in fact returning empty arrays.
After troubleshooting, I realized it was in fact the DIR that was set to the relative file of
mecab.py, but thus it wouldn't find the dictionnary that were downloaded in the cloned repository.By adding a env variable, and also suggesting to used to just hardcode it if it's easier for them, I was able to make parsing work differently
Before : See how the parsed results is an empty array

After, now the result is filled correctly
