回答:
これは、TensorFlowのインストール方法によって異なります。この回答を構成するために、TensorFlowのインストール手順で使用されているのと同じ見出しを使用します。
実行:
python -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 3
ご了承ください pythonにシンボリックリンクされている/usr/bin/python3いくつかのLinuxディストリビューションでは、これを使用pythonするのではなく、python3これらのケースで。
pip list | grep tensorflowPython 2またはpip3 list | grep tensorflowPython 3の場合は、インストールされているTensorflowのバージョンも表示されます。
実行:
python -c 'import tensorflow as tf; print(tf.__version__)' # for both Python 2 and Python 3
pip list | grep tensorflow インストールされているTensorflowのバージョンも表示されます。
たとえばvirtualenv、Python 3のTensorFlow 0.9.0をインストールしたので、次のようになります。
$ python -c 'import tensorflow as tf; print(tf.__version__)'
0.9.0
$ pip list | grep tensorflow
tensorflow (0.9.0)
git rev-parse HEAD
'module' object has no attribute '__version__'ときpython -c 'import tensorflow as tf; print(tf.__version__)'
"の代わりに、':python3 -c "import tensorflow as tf; print(tf.__version__)"
Pythonのほとんどすべての通常のパッケージは、変数.__version__またはVERSION現在のバージョンに変数を割り当てます。だから、あなたがいくつかのパッケージのバージョンを見つけたいなら、あなたは以下をすることができます
import a
a.__version__ # or a.VERSION
tensorflowの場合は
import tensorflow as tf
tf.VERSION
tensorflowの古いバージョン(0.10未満)の場合は、 tf.__version__
pipでインストールした場合は、次のコマンドを実行してください。
$ pip show tensorflow
Name: tensorflow
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
pip show tensorflow-gpuGPUバージョン用。さらに良いのは、やるだけですpip list | grep tensorflow。
import tensorflow as tf
print(tf.VERSION)
Python 3.6.2の場合:
import tensorflow as tf
print(tf.version.VERSION)
tensorflowとそのオプションに関する詳細情報を取得するには、以下のコマンドを使用できます。
>> import tensorflow as tf
>> help(tf)
TensorFlow 2.xを使用している場合:
sess = tf.compat.v1.Session(config = tf.compat.v1.ConfigProto(log_device_placement = True))
pip show [package name]例えば:pip show tensorflow、pip show numpyなど