38
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pip install したパッケージをimport できないときの対応

Last updated at Posted at 2015-08-23

環境:OSX Yosemite 10.10.3
Python : 2.7

機械学習のライブラリscikit-learnを利用しようとしたとき

$ pip install -U scikit-learn
(省略)
Successfully installed sklearn Cleaning up...

で見事インストール成功かとおもいきや

$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn import datasets
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn

エラー、、

調べてみるとOSXではpythonは標準で搭載されている方のライブラリを見に行ってるっぽいことが判明

参考
Cannot import scikits-learn even though it seems to be installed
(stackoverflow)

標準の方のパスが
/Library/Python/2.7/site-packages/
pipでインストールした方のパスが
/usr/local/lib/python2.7/site-packages/

確かに/usr/local/lib/python2.7/site-packages/にはちゃんとscikit-learn入ってるじゃんということでパスを通す

##パスの通し方##

~/.bashrc
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/```

参考
ImportError: No module named sklearn.datasets

PYTHONPATHなんていう環境変数があったのか。
これで無事importしたパッケージが使えるようになったので一安心

38
36
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
38
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?