我需要找到我安装了哪个版本的TensorFlow。我使用的是Ubuntu 16.04长期支持。


当前回答

这取决于你是如何安装TensorFlow的。我将使用TensorFlow安装说明中使用的相同标题来构造这个答案。


Pip安装

Run:

python -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 3

注意,在某些Linux发行版中,python是符号链接到/usr/bin/python3的,所以在这些情况下使用python而不是python3。

pip list | grep tensorflow for python2或pip3 list | grep tensorflow for python3也将显示安装的tensorflow版本。


Virtualenv安装

Run:

python -c 'import tensorflow as tf; print(tf.__version__)'  # for both Python 2 and Python 3

pip list | grep tensorflow也会显示安装的tensorflow版本。

例如,我已经在Python 3的virtualenv中安装了TensorFlow 0.9.0。所以,我得到:

$ python -c 'import tensorflow as tf; print(tf.__version__)'
0.9.0

$ pip list | grep tensorflow
tensorflow (0.9.0)

其他回答

我从源代码安装了Tensorflow 0.12rc,下面的命令给了我版本信息:

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 -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 3

这里-c表示作为字符串传入的程序(终止选项列表)

打印人类可读格式的python版本

python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))'

这取决于你是如何安装TensorFlow的。我将使用TensorFlow安装说明中使用的相同标题来构造这个答案。


Pip安装

Run:

python -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 3

注意,在某些Linux发行版中,python是符号链接到/usr/bin/python3的,所以在这些情况下使用python而不是python3。

pip list | grep tensorflow for python2或pip3 list | grep tensorflow for python3也将显示安装的tensorflow版本。


Virtualenv安装

Run:

python -c 'import tensorflow as tf; print(tf.__version__)'  # for both Python 2 and Python 3

pip list | grep tensorflow也会显示安装的tensorflow版本。

例如,我已经在Python 3的virtualenv中安装了TensorFlow 0.9.0。所以,我得到:

$ python -c 'import tensorflow as tf; print(tf.__version__)'
0.9.0

$ pip list | grep tensorflow
tensorflow (0.9.0)

对于python 3.6.2:

import tensorflow as tf

print(tf.version.VERSION)