0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Apple Silicon の Macで発生する ImportError: The 'enchant' C library was not found and maybe needs to be installed. の対処方法

Last updated at Posted at 2025-02-21

軽い前置き

何について書いているのか

  • Apple SiliconのMacを使っていて、英語のスペルチェッカーであるenchantを使いたいが、rosetta を使えという対処法しか見つからず、処理速度が遅くて唸っている人向けの enchant の入れ方です
  • 結論から言うと、rosetta使わなくても入れることが出来ます

主要なコマンド

brew install enchant
poetry add pyenchant
export PYENCHANT_LIBRARY_PATH=/opt/homebrew/Cellar/enchant/2.8.2/lib/libenchant-2.2.dylib

です。
以下のソースコードで動作確認してオッケーなら、ちゃんと入っています

import enchant
d = enchant.Dict("en_US")
d.check("Hello") # True
d.check("Helo") # False

何をやっているのか

1行目

brew install enchant
  • enchant(英語のスペルチェッカー)を入れています。
  • ここにある通り、最新版がHomebrewで配信されており、macOSでも動くようになっています
  • PyEnchantEnchantのリンクが切れており、たどり着けない方がいるようです

2行目

poetry add pyenchant
  • poetry使っている前提になっていますがpipでも一緒です、たぶん。

3行目

export PYENCHANT_LIBRARY_PATH=/opt/homebrew/Cellar/enchant/2.8.2/lib/libenchant-2.2.dylib
  • PyEnchantが読みに行くパスを設定してあげることで、読めるようになります

背景

意地でもrosetta使いたくないマン

  • 私は意地でもrosetta使いたくないマンです
  • だって遅いんだもん
  • 他にもEC2でもArmを選択したいとか、raspiで動かしたいとか、いろいろ邪念が多いようです

rosettaを使えというissue

  • Apple Silicon 出始めに作られたこちらのissueを見に行ってしまうケースが多いようです
  • 出てからもう何年も経ってるからさすがに対応されてるだろJK、ってことでここでも意地を張ります

pypiにAppleSiliconバイナリが上がっていない

  • バイナリ付きのwhlはWindows向けしか上がっていないんですよね
  • 逆に言うとMac向けのは無さそうに見えちゃいます
  • また、最終更新も2021年と古く、「最近更新されてないのかなぁ」という思い込みを生じやすいです

自力でビルドしてインストールする場合

  • ここにソースが上がっているのでbuildしてもセットアップできます

groffを入れる

  • groffを入れていない場合は brew install groff を実行しましょう

INSTALLに記載のあるコマンド

 test -f configure || ./bootstrap
 ./configure
 make
 make install

上記を実行すると以下ができるので、

/usr/local/lib/libenchant-2.2.dylib
/usr/local/lib/libenchant-2.dylib

PYENCHANT_LIBRARY_PATHを設定してdynamicに読む設定をしてあげると、動きます

最後に

  • 上記の通り、わりと罠が多めなので、注意しましょう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?