问题:如何找到我的系统中安装了哪个版本的TensorFlow?
我需要找到已安装的TensorFlow版本。我正在使用Ubuntu 16.04长期支持。
I need to find which version of TensorFlow I have installed. I’m using Ubuntu 16.04 Long Term Support.
回答 0
这取决于您安装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
请注意,在某些Linux发行版中,它python
是符号链接的/usr/bin/python3
,因此在这些情况下,请使用python
代替python3
。
pip list | grep tensorflow
适用于Python 2或pip3 list | grep tensorflow
适用于Python 3的版本还将显示已安装的Tensorflow的版本。
Virtualenv安装
跑:
python - c 'import tensorflow as tf; print(tf.__version__)' # for both Python 2 and Python 3
pip list | grep tensorflow
还将显示已安装的Tensorflow的版本。
例如,我已经在virtualenv
Python 3的a中安装了TensorFlow 0.9.0 。因此,我得到:
$ python - c 'import tensorflow as tf; print(tf.__version__)'
0.9 . 0
$ pip list | grep tensorflow
tensorflow ( 0.9 . 0 )
This depends on how you installed TensorFlow. I am going to use the same headings used by TensorFlow’s installation instructions to structure this answer.
Pip installation
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
Note that python
is symlinked to /usr/bin/python3
in some Linux distributions, so use python
instead of python3
in these cases.
pip list | grep tensorflow
for Python 2 or pip3 list | grep tensorflow
for Python 3 will also show the version of Tensorflow installed.
Virtualenv installation
Run:
python -c 'import tensorflow as tf; print(tf.__version__)' # for both Python 2 and Python 3
pip list | grep tensorflow
will also show the version of Tensorflow installed.
For example, I have installed TensorFlow 0.9.0 in a virtualenv
for Python 3. So, I get:
$ python -c 'import tensorflow as tf; print(tf.__version__)'
0.9.0
$ pip list | grep tensorflow
tensorflow (0.9.0)
回答 1
python中几乎每个普通软件包都将变量.__version__
或分配VERSION
给当前版本。因此,如果要查找某些软件包的版本,可以执行以下操作
import a
a . __version__ # or a.VERSION
对于张量流它将是
import tensorflow as tf
tf . VERSION
对于旧版本的tensorflow(低于0.10),请使用 tf.__version__
顺便说一句,如果您打算安装TF,请使用conda而不是pip进行安装
Almost every normal package in python assigns the variable .__version__
to the current version. So if you want to find the version of some package you can do the following
import a
a.__version__
For tensorflow it will be
import tensorflow as tf
tf.version.VERSION
For old versions of tensorflow (below 0.10), use tf.__version__
回答 2
如果您是通过pip安装的,则只需运行以下命令
$ pip show tensorflow
Name : tensorflow
Version : 1.5 . 0
Summary : TensorFlow helps the tensors flow
If you have installed via pip, just run the following
$ pip show tensorflow
Name: tensorflow
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
回答 3
import tensorflow as tf
print ( tf . VERSION )
import tensorflow as tf
print(tf.VERSION)
回答 4
如果您使用的是Python的anaconda发行版,
$ conda list | grep tensorflow
tensorflow 1.0 . 0 py35_0 conda - forge
使用Jupyter Notebook(IPython Notebook)进行检查
In [ 1 ]: import tensorflow as tf
In [ 2 ]: tf . __version__
Out [ 2 ]: '1.0.0'
If you’re using anaconda distribution of Python,
$ conda list | grep tensorflow
tensorflow 1.0.0 py35_0 conda-forge
To check it using Jupyter Notebook (IPython Notebook)
In [1]: import tensorflow as tf
In [2]: tf.__version__
Out[2]: '1.0.0'
回答 5
对于python 3.6.2:
import tensorflow as tf
print ( tf . version . VERSION )
For python 3.6.2:
import tensorflow as tf
print(tf.version.VERSION)
回答 6
我从源代码安装了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
下图显示了输出:
I installed the Tensorflow 0.12rc from source, and the following command gives me the version info:
python -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 3
The following figure shows the output:
回答 7
在最新的TensorFlow版本1.14.0上
tf.VERSION
已弃用,而不是此用法
tf.version.VERSION
错误:
WARNING : Logging before flag parsing goes to stderr .
The name tf . VERSION is deprecated . Please use tf . version . VERSION instead .
On Latest TensorFlow release 1.14.0
tf.VERSION
is deprecated, instead of this use
tf.version.VERSION
ERROR:
WARNING: Logging before flag parsing goes to stderr.
The name tf.VERSION is deprecated. Please use tf.version.VERSION instead.
回答 8
要获取有关tensorflow及其选项的更多信息,可以使用以下命令:
>> import tensorflow as tf
>> help ( tf )
To get more information about tensorflow and its options you can use below command:
>> import tensorflow as tf
>> help(tf)
回答 9
轻松获得KERAS和TENSORFLOW版本号->在终端中运行以下命令:
[用户名@usrnm:〜] python3
>>import keras; print(keras.__version__)
Using TensorFlow backend.
2.2.4
>>import tensorflow as tf; print(tf.__version__)
1.12.0
Easily get KERAS and TENSORFLOW version number –>
Run this command in terminal:
[username@usrnm:~] python3
>>import keras; print(keras.__version__)
Using TensorFlow backend.
2.2.4
>>import tensorflow as tf; print(tf.__version__)
1.12.0
回答 10
tensorflow版本可以在终端或控制台上检查,也可以在任何IDE编辑器中检查(例如Spyder或Jupyter笔记本等)
简单命令检查版本:
( py36 ) C : \WINDOWS\system32 > python
Python 3.6 . 8 | Anaconda custom ( 64 - bit )
>>> import tensorflow as tf
>>> tf . __version__
'1.13.1'
The tensorflow version can be checked either on terminal or console or in any IDE editer as well (like Spyder or Jupyter notebook, etc)
Simple command to check version:
(py36) C:\WINDOWS\system32>python
Python 3.6.8 |Anaconda custom (64-bit)
>>> import tensorflow as tf
>>> tf.__version__
'1.13.1'
回答 11
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 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 3
Here -c represents program passed in as string (terminates option list)
回答 12
Jupyter Notebook中的Tensorflow版本:-
! pip list | grep tensorflow
Tensorflow version in Jupyter Notebook:-
!pip list | grep tensorflow
回答 13
如果您具有TensorFlow 2.x:
sess = tf.compat.v1.Session(config = tf.compat.v1.ConfigProto(log_device_placement = True))
If you have TensorFlow 2.x:
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))
回答 14
我猜是另一种变化:P
python3 -c 'print(__import__("tensorflow").__version__)'
Another variation, i guess :P
python3 -c 'print(__import__("tensorflow").__version__)'