Pythonプログラミング:virtualenvにpolyglotをインストール

その買うを、もっとハッピーに。|ハピタス

polyglotを仮想環境にインストールするのはかなりの手間がかかる。polyglot moduleのインストは[cciNe lang=”bash” theme=”blackboard”]pip install polyglot[/cciNe]で簡単に出来るが、モジュールをインポートすると
[cce lang=”python” tab_size=”2″ lines=”40″ theme=”mac_classic”]from polyglot.text import Text[/cce] icu moduleがないエラーが出た。このエラーは、[cciNe lang=”bash” theme=”blackboard”]sudo apt-get install libicu-dev[/cciNe]では解消されない。pyicuというmoduleをインストール必要があり、[cciNe lang=”bash” theme=”blackboard”]pip install pyicu[/cciNe]でインストールを試みるも、無情にもicu-configがないとエラーが出る。とりあえずpyicuをインストールする前に最新のicuをインストールしてみることにした。

最新版のicuをソースからインストールする。
[cce lang=”bash” theme=”mac_classic”]wget http://download.icu-project.org/files/icu4c/61.1/icu4c-61_1-src.tgz
tar -xvzf icu4c-61_1-src.tgz
cd icu/source
./configure –prefix=/usr CXX=clang++ CC=clang
make
make install[/cce] 次にpyicuをvirtualenvにインストールする。
[cce lang=”bash” theme=”geshi”]git clone https://github.com/ovalhub/pyicu.git
cd pyicu
CFLAGS=-I/usr/include LDFLAGS=-L/usr/lib/icu/ ~/.pyenv/versions/3.6.4/envs/py36/bin/python setup.py build
CFLAGS=-I/usr/include LDFLAGS=-L/usr/lib/icu/ ~/.pyenv/versions/3.6.4/envs/py36/bin/python setup.py install[/cce] これだけやってもまだ以下のようなエラーが吐き出される。
[ccNe lang=”bash” theme=”solarized-light”]undefined symbol: _ZTIN6icu_5714LEFontInstanceE[/ccNe] このエラーを以下のようにやるしか解消できないようだ。
[ccNe lang=”bash” theme=”mac_classic”]sudo apt install libicu55 python3-icu icu-devtools
rm -rf ~/.pyenv/versions/3.6.4/envs/py36/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-linux-x86_64.egg/_icu.cpython-36m-x86_64-linux-gnu.so
ln -s /usr/lib/python3/dist-packages/_icu.cpython-35m-x86_64-linux-gnu.so ~/.pyenv/versions/3.6.4/envs/py36/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-linux-x86_64.egg/_icu.cpython-36m-x86_64-linux-gnu.so[/ccNe] これだけやってもまだ以下のようなエラーが吐き出された。
[ccNe lang=”bash” theme=”solarized-light”]ModuleNotFoundError: No module named ‘morfessor'[/ccNe] このエラーは、[cciNe lang=”bash” theme=”blackboard”]pip install morfessor[/cciNe]で簡単に解消された。
やっとpolyglotのインストールが完了した。一筋縄ではいかないのが辛いところだ。
[cce lang=”python” tab_size=”2″ lines=”40″ theme=”mac_classic”]from polyglot.text import Text
blob = “””We will meet at eight o’clock on Thursday morning.”””
text = Text(blob)
for x in text.transliterate(“ja”):
print(x)
[/cce] [ccNe lang=”bash” theme=”solarized-light”]ウェ
ウィル
メート
アト
ーイト
オクロック
オン
トハースダイ
モーニング[/ccNe] 参考サイトhttps://stackoverflow.com/
参考サイトhttps://github.com/

スポンサーリンク
スポンサーリンク