SamuraiT / mecab-python3

:snake: mecab-python. you can find original version here:http://taku910.github.io/mecab/
https://pypi.python.org/pypi/mecab-python3
Other
541 stars 51 forks source link

M1 wheels are not available #84

Closed polm closed 1 year ago

polm commented 2 years ago

There are no wheels for the OSX M1 / arm64 architecture. They are not available because I do not have a way to automate builds.

Please see https://github.com/polm/fugashi/issues/55#issuecomment-1158463940 for more details and progress updates.

Note that in the meantime you have two options:

  1. Build MeCab from source before installing mecab-python3. I believe this should just work, and it's straightforward if you're familiar with autotools builds. (It should also work if you install with brew install mecab first.)
  2. Use x86_64 Python on the M1. I believe this is less efficient, but it may be easier in some cases.
gokalper commented 2 years ago

Leaving this incase anyone else can benefit:

I was able to compile it myself using the following on an M1 Mac:

pip3 download mecab-python3
tar xfv mecab-python3-1.0.5.tar.gz
cd mecab-python3-1.0.5    
brew install mecab
python3 setup.py build
python3 setup.py install
pip3 list
amitkot commented 2 years ago

For me this was the missing part:

brew install mecab
polm commented 2 years ago

I'm not familiar with the brew distribution of MeCab, but that is one way to install it instead of building directly from source. If you use their version you should check if they've patched it in any way.

agilebean commented 1 year ago

I'm not familiar with the brew distribution of MeCab, but that is one way to install it instead of building directly from source. If you use their version you should check if they've patched it in any way.

I can confirm that building by source does not work, but the above answers to build mecab with brew do work successfully on an M1 CPU

polm commented 1 year ago

When you say building from source does not work, what do you mean? What error do you get?

Note that installing MeCab from source is a separate step before building mecab-python3 from source.

agilebean commented 1 year ago

When you say building from source does not work, what do you mean? What error do you get?

Note that installing MeCab from source is a separate step before building mecab-python3 from source.

@polm Following the solution by @gokalper with pip3 download mecab-python3, the current version downloaded throws a compatibility issue:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tts 0.9.0 requires mecab-python3==1.0.5, but you have mecab-python3 1.0.6 which is incompatible.

So you need to know before to install by: pip install mecab-python3==1.0.5

agilebean commented 1 year ago

Adding to homebrew solution suggested, it is essential that

  1. you use the version of homebrew for Apple silicon (get it from homebrew homepage).
  2. you envoke homebrew by the Apple Silicon flags: /opt/homebrew/bin/brew

The last point is essential if you use another homebrew installation for the intel architecture.

polm commented 1 year ago

What is the actual error you get if you build MeCab from source first? Using brew is also fine, but it still isn't clear to me what went wrong just building from source.

The "compatibility issue" you mention seems to be a conflict with the requirements of tts, a text to speech package, that has pinned a specific older version of this library. That is not a bug, and it only affects users of tts. Also note it's a warning - the code should work anyway, since the only change in 1.0.6 was adding 3.11 wheels.

It makes sense that you would use the M1 version of brew if you want an M1 build.

agilebean commented 1 year ago

What is the actual error you get if you build MeCab from source first? Using brew is also fine, but it still isn't clear to me what went wrong just building from source.

The "compatibility issue" you mention seems to be a conflict with the requirements of tts, a text to speech package, that has pinned a specific older version of this library. That is not a bug, and it only affects users of tts.

Yes you're right. I realized that after posting this.

Also note it's a warning - the code should work anyway, since the only change in 1.0.6 was adding 3.11 wheels.

Good to know.

It makes sense that you would use the M1 version of brew if you want an M1 build.

So I think you can close this issue then

polm commented 1 year ago

OK, thanks for clarifying. This issue is not just about using the package on M1 machines, it's about my ability to provide wheels. If you want to stay updated on progress you can subscribe to it, and when Github Actions or some other method becomes available I'll update this.

For now I'll hide all these comments, since they're off topic.

polm commented 1 year ago

Looking over this again, it just occurred to me that I should clearly state I expect this should work:

brew install mecab
pip install mecab-python3

I don't have a Mac to check this, but you shouldn't have to do the pip download and other steps - pip will install from source by default if it can't find a wheel. (I guess this is what @amitkot was saying upthread.)

agilebean commented 1 year ago

@polm Yes you're right. However, on Apple Silicon, you need to force both commands to compile from source, as mentioned here

/opt/homebrew/bin/brew install mecab --build-from-source

ARCHFLAGS='-arch arm64' pip install --compile --use-pep517 --no-cache-dir --force" mecab-python3==1.0.5
BenQuigley commented 1 year ago

@agilebean just a small correction, there is a misplaced double quote in your command; I think it should be

/opt/homebrew/bin/brew install mecab --build-from-source
pip install unidic-lite  # in case someone missed it from the README
ARCHFLAGS='-arch arm64' pip install --compile --use-pep517 --no-cache-dir --force mecab-python3==1.0.5
yin-ori commented 1 year ago

@BenQuigley this will run me into an error:

ARCHFLAGS='-arch arm64' pip install --compile --use-pep517 --no-cache-dir --force mecab-python3==1.0.5
Collecting mecab-python3==1.0.5
  Downloading mecab-python3-1.0.5.tar.gz (77 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.6/77.6 kB 884.4 kB/s eta 0:00:00
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Collecting setuptools>=40.8.0
        Using cached setuptools-67.8.0-py3-none-any.whl (1.1 MB)
      Collecting wheel
        Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
      Installing collected packages: wheel, setuptools
      ERROR: Cannot set --home and --prefix together
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
ariqRam commented 1 year ago

tar xfv mecab-python3-1.0.5.tar.gz

Worked for my M1!

yin-ori commented 1 year ago

yes, I needed to install and not build from scratch, then it worked for me too :-)

polm commented 1 year ago

This should be resolved in fugashi thanks to https://github.com/polm/fugashi/pull/80. I have just made a release there, and if that goes smoothly I will port the M1 build over here eventually.

polm commented 1 year ago

I have made an alpha release that includes what I think are working M1 wheels. You can install it like so:

pip install mecab-python3==1.0.8a1

If I can get some confirmation that this works I will make a release.

cadazar commented 1 year ago

@polm Just tried installing on M2 using Python 3.11 and it works great!

polm commented 1 year ago

Thank you for the confirmation, I have made a 1.0.8 release with the wheels, which should be available shortly.

polm commented 1 year ago

This has been released. Thanks to everyone who provided advice to users inconvenienced by this issue.