LoginSignup
0
1

More than 3 years have passed since last update.

Tensorflowをインストールしたがno moduleエラーが発生する件について

Posted at

はじめに

久しぶりにtensorflowをインストールしたのですが、なぜかインポートできず(tensorflowがないよと言われる)、解決方法がすぐに見つからなかったため記事にしました。普段意識していないところが原因でしたので、まとめておきます。

環境

  • python3.8
  • Docker
  • jupyter notebook

問題

!pip install tensorflow
import tensorflow as tf

を実行すると、以下のよエラーが発生する

1619405942.png

この記事を確認したところ--userをつけることで権限をつけることでインストール先を~./localに変更できる。
https://boook24.com/?p=518

!pip install tensorflow --user
import tensorflow as tf

を実行するとなぜかno moduleエラーとなる。インストールしているのになぜとなった。

1619405987.png

解決方法

!pip istallはPython2にインストールするが、python3のライブラリを読み込んでいるので、!pip3 installとする必要があった。

!pip3 install tensorflow
import tensorflow as tf

で無事読み込むことができました。

終わりに

pipとcondaの共存やpipとpip3の違いなど、どこにエラーの原因が潜んでいるかなかなか難しいです。

0
1
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
1