Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

環境: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したパッケージが使えるようになったので一安心

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした