HugoFara / lwt

Learn languages by reading! A language learning app stemmed from Learning with Texts (LWT).
https://hugofara.github.io/lwt/
The Unlicense
168 stars 19 forks source link

OS 'DAR' not found for MeCab #135

Closed HugoFara closed 5 months ago

HugoFara commented 1 year ago

when I open a text now, it shows the following...

Fatal Error: Your OS 'DAR' cannot use MeCab with this version of LWT!

Backtrace:

0 /Applications/MAMP/htdocs/lwt-2.8.1/inc/kernel_utility.php(268): my_die('Your OS 'DAR' c...')

1 /Applications/MAMP/htdocs/lwt-2.8.1/inc/session_utility.php(4498): get_mecab_path(' -O yomi ')

2 /Applications/MAMP/htdocs/lwt-2.8.1/do_text_header.php(186): phonetic_reading('\xE8\x8C\xA8\xE5\x9F\x8E\xE7\x9C\x8C\xE3\x81\xAE\xE7\xB4\x8D...', 'ja')

3 /Applications/MAMP/htdocs/lwt-2.8.1/do_text_header.php(313): browser_tts('\xE8\x8C\xA8\xE5\x9F\x8E\xE7\x9C\x8C\xE3\x81\xAE\xE7\xB4\x8D...', 'Japanese')

4 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(96): do_text_header_content(3, true)

5 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(144): do_text_desktop_content(3)

6 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(150): do_text_page(3)

Originally posted by @quopquai in https://github.com/HugoFara/lwt/issues/134#issuecomment-1624704329

@quopquai is using a Mac M2.

HugoFara commented 1 year ago

Hmmm, it seems I never tried MeCab with a Mac as I don't own one. I may ask you a small contribution @quopquai :smile:

First, did you install MeCab? It is not shipped with LWT and needs to be installed separately.

Second, can you open a terminal and tell me if this command works command -v mecab please? If so, I may add a support for MeCab Mac...

quopquai commented 1 year ago

...a contribution, sure, that sounds reasonable...!

I have no idea if I installed it or not!? I might have!?

...when I type the command, nothing seems to happen...

Screenshot 2023-07-07 at 13 41 38
HugoFara commented 1 year ago

Okay, so MeCab is not installed. You need to install it first, and the previous command returns the location of the binary. Unfortunately I cannot recommend you a good tutorial as I don't have a Mac, but I already read that you can install it with homebrew.

Once that's done, we can work one an integration of MeCab for Mac!

quopquai commented 1 year ago

...ok I think I've done it...

Screenshot 2023-07-07 at 13 57 52
HugoFara commented 1 year ago

Nice! Let's perform some live surgery on LWT!

Can you go to line 250 of kernel_utility.php (/Applications/MAMP/htdocs/lwt-2.8.1/inc/kernel_utility.php(268)), and do the following substitution?

From

if ($os == 'LIN') {

to

if ($os == 'LIN' || $os == 'DAR') {

If MeCab works with that, I'm adding the feature!

EDIT: just to explain a bit $os is you OS name ("LIN" for Linux, "DAR" for Darwin (Mac)...), so here we tell LWT to behave the same with Linux and Mac (|| means "or").

quopquai commented 1 year ago

...I changed it...and saved...

Screenshot 2023-07-07 at 14 12 34

lwt is giving me this now:

Fatal Error: MeCab not detected! Please install it and add it to your PATH.

Backtrace:

0 /Applications/MAMP/htdocs/lwt-2.8.1/inc/kernel_utility.php(254): my_die('MeCab not detec...')

1 /Applications/MAMP/htdocs/lwt-2.8.1/inc/session_utility.php(4498): get_mecab_path(' -O yomi ')

2 /Applications/MAMP/htdocs/lwt-2.8.1/do_text_header.php(186): phonetic_reading('[7\xE6\x9C\x884\xE6\x97\xA5 16\xE6\x99\x82...', 'ja')

3 /Applications/MAMP/htdocs/lwt-2.8.1/do_text_header.php(313): browser_tts('[7\xE6\x9C\x884\xE6\x97\xA5 16\xE6\x99\x82...', 'Japanese')

4 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(96): do_text_header_content(1, true)

5 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(144): do_text_desktop_content(1)

6 /Applications/MAMP/htdocs/lwt-2.8.1/do_text.php(150): do_text_page(1)

HugoFara commented 1 year ago

I think you installed MeCab on your computer, but MAMP cannot access its path and cannot find it. I'm not sure about how to solve it :thinking:

I'm looking online...

HugoFara commented 1 year ago

Please install it and add it to your PATH.

By the way, did you do that?

quopquai commented 1 year ago

...no, how do you do that?

HugoFara commented 1 year ago

I'm copy/pasting from https://apple.stackexchange.com/questions/41542/adding-a-new-executable-to-the-path-environment-variable

In your case, you can add usr/local/bin/mecab, then reload the server. I hope that will work :no_mouth:

quopquai commented 1 year ago

I'm sorry for the delay:

Macintosh:~ julisco$ usr/local/bin/mecab -bash: usr/local/bin/mecab: No such file or directory Macintosh:~ julisco$

I have no idea what is going on?!

HugoFara commented 1 year ago

I cannot be sure... I think the best solution for now is to try having a working instance of MeCab, then run LWT, and if it doesn't work you may need to configure MAMP to use the good path (I'm really not sure how MAMP works)...

quopquai commented 1 year ago

I found this in my terminal when installing MeCab:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

does it mean anything?

HugoFara commented 1 year ago

I have no idea what that is, sorry :disappointed:

quopquai commented 1 year ago

https://github.com/jzohrab/lute/wiki/Mecab-and-Apache

MAMP (Mac users) Run the following in terminal to adjust the MAMP Apache server PATH:

printf 'export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"' >> /Applications/MAMP/Library/bin/envvars

...finally jz from LUTE gave me the solution. ...now everything seems to work fine on Mac.

Thanks again HugoFara!!! :)

ProgramComputer commented 8 months ago

@HugoFara

printf 'export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"' >> /Applications/MAMP/Library/bin/envvars

Add this in docs and close issue.