Python
GCC
scipy
scikit-learn
Pycharm

[PyCharm] Symbol not found: ___addtf3

PyCharmでscikit-learnをimport するときにimport errorが出たのでメモ.

エラー内容

Traceback (most recent call last):
  File "/Users/sasayabaku/PycharmProjects/Kmeans/kmeans.py", line 7, in <module>
    from sklearn.cluster import KMeans
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/sklearn/__init__.py", line 134, in <module>
    from .base import clone
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/sklearn/base.py", line 12, in <module>
    from .utils.fixes import signature
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/sklearn/utils/__init__.py", line 11, in <module>
    from .validation import (as_float_array,
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/sklearn/utils/validation.py", line 18, in <module>
    from ..utils.fixes import signature
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/sklearn/utils/fixes.py", line 144, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr  # noqa
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/__init__.py", line 113, in <module>
    from .isolve import *
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
    from .iterative import *
  File "/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
    from . import _iterative
ImportError: dlopen(/Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/isolve/_iterative.cpython-36m-darwin.so, 2): Symbol not found: ___addtf3
  Referenced from: /Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/isolve/../../../.dylibs/libquadmath.0.dylib
  Expected in: /usr/lib/libSystem.B.dylib
 in /Users/sasayabaku/.pyenv/versions/3.6.0/lib/python3.6/site-packages/scipy/sparse/linalg/isolve/../../../.dylibs/libquadmath.0.dylib

Symbol "__addtf3" not foundって言われてます.

解決方法

これは,gccでgfortranというライブラリが必要になるらしい.

環境変数DYLD_LIBRARY_PATHにパスを指定したら,上手にいけました!!

export DYLD_LIBRARY_PATH="/usr/local/opt/gcc/lib/gcc/6"

この環境変数を設定して,PyCharmを再起動すると,PyCharm内の環境変数が設定されるので,私はscikit-learnのimportができました.

参考文献

Where does pip install libraries compared to where python from terminal runs?:stackoverflow