Come trovare quale versione di TensorFlow è installata nel mio sistema?


260

Devo trovare quale versione di TensorFlow ho installato. Sto usando il supporto a lungo termine di Ubuntu 16.04.


6
Per prelevare il riepilogo (incl versione del pacchetto.) Provare: pip show [package name], ad esempio: pip show tensorflow, pip show numpyecc
— Sumanth Lazzaro

4
Semplicementeprint(tf.__version__)
— Pe Dro

Risposte:


421

Questo dipende da come hai installato TensorFlow. Userò le stesse intestazioni usate dalle istruzioni di installazione di TensorFlow per strutturare questa risposta.


Installazione Pip

Correre:

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

Si noti che pythonè collegato in modo simbolico ad /usr/bin/python3alcune distribuzioni Linux, quindi utilizzare pythoninvece python3in questi casi.

pip list | grep tensorflowper Python 2 o pip3 list | grep tensorflowper Python 3 mostrerà anche la versione di Tensorflow installata.


Installazione di Virtualenv

Correre:

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

pip list | grep tensorflow mostrerà anche la versione di Tensorflow installata.

Ad esempio, ho installato TensorFlow 0.9.0 in a virtualenvper Python 3. Quindi ottengo:

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

$ pip list | grep tensorflow
tensorflow (0.9.0)

3
e se stai costruendo dal sorgente, la tua versione è commit hash fromgit rev-parse HEAD
— Yaroslav Bulatov,

5
Capito 'module' object has no attribute '__version__'quandopython -c 'import tensorflow as tf; print(tf.__version__)'
— user3768495

1
@ user3768495 Se hai installato Tensorflow con VirtualEnv devi attivare l'ambiente e questo deve essere fatto per ogni nuova console che apri (sorgente ~ / tensorflow / bin / activ). Una volta fatto puoi recuperare la tua versione di tensorflow (elenco pip | grep tensorflow)
— Nestor Urquiza,

5
per Windows CMD è necessario utilizzare la virgoletta doppia "anziché ':python3 -c "import tensorflow as tf; print(tf.__version__)"
— user924

1
[esempi jalal @ goku] $ python -c 'import tensorflow as tf; print (tf .__ version__) 'Traceback (ultima chiamata più recente): file "<string>", riga 1, in <module> AttributeError: il modulo' tensorflow 'non ha attributi' versione '
— Mona Jalal

74

Quasi ogni pacchetto normale in python assegna la variabile .__version__o VERSIONalla versione corrente. Quindi se vuoi trovare la versione di alcuni pacchetti puoi fare quanto segue

import a
a.__version__ # or a.VERSION

Per tensorflow lo sarà

import tensorflow as tf
tf.VERSION

Per le versioni precedenti di tensorflow (inferiore a 0,10), utilizzare tf.__version__

A proposito, se hai intenzione di installare tf, installalo con conda, non pip


7
tf.VERSION non funziona per TF2.0. Tuttavia, tf .__ versione__ funziona bene.
— apatsekin,

42

Se è stato installato tramite pip, eseguire semplicemente quanto segue

$ pip show tensorflow
Name: tensorflow
Version: 1.5.0
Summary: TensorFlow helps the tensors flow

pip show tensorflow-gpuper la versione GPU. Meglio ancora, basta pip list | grep tensorflow.
— user1857492,

1
Questo è un brillante comando per ottenere un riepilogo per qualsiasi pacchetto python!
— Sumanth Lazzaro,

30
import tensorflow as tf

print(tf.VERSION)

Grazie Bilal. Funziona con versioni precedenti alla 1.0
— Yuchao Jiang,

print () tra parentesi è una cosa python3, non necessaria per python2.
— David Skarbrevik,

16

Se stai usando la distribuzione anaconda di Python,

$ conda list | grep tensorflow
tensorflow    1.0.0       py35_0    conda-forge

Per controllarlo utilizzando Jupyter Notebook (Notebook IPython)

In [1]: import tensorflow as tf
In [2]: tf.__version__
Out[2]: '1.0.0'

16

Per python 3.6.2:

import tensorflow as tf

print(tf.version.VERSION)

print (tf .__ versione__) funziona in tf2.0 rc (py 3.7.4)
— Prabindh

8

Ho installato Tensorflow 0.12rc dal sorgente e il seguente comando mi dà le informazioni sulla versione:

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

La seguente figura mostra l'output:

inserisci qui la descrizione dell'immagine


5

Nella versione più recente di TensorFlow 1.14.0

tf.VERSION

è deprecato, invece di questo uso

tf.version.VERSION

ERRORE:

WARNING: Logging before flag parsing goes to stderr.
The name tf.VERSION is deprecated. Please use tf.version.VERSION instead.

4

Per ottenere maggiori informazioni su tensorflow e le sue opzioni è possibile utilizzare il comando seguente:

>> import tensorflow as tf
>> help(tf)

1
Ottengo python3.6 -c 'import tensorflow come tf; help (tf) 'Errore di segmentazione (core scaricato)
— John Jiang,

3

Ottieni facilmente il numero di versione di KERAS e TENSORFLOW -> Esegui questo comando nel terminale:

[nomeutente @ usrnm: ~] python3

>>import keras; print(keras.__version__)

Using TensorFlow backend.

2.2.4

>>import tensorflow as tf; print(tf.__version__)

1.12.0


2

La versione tensorflow può essere verificata sul terminale o sulla console o in qualsiasi editor IDE (come Spyder o Jupyter, ecc.)

Semplice comando per verificare la versione:

(py36) C:\WINDOWS\system32>python
Python 3.6.8 |Anaconda custom (64-bit)

>>> import tensorflow as tf
>>> tf.__version__
'1.13.1'

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

Qui -c rappresenta il programma passato come stringa (termina l'elenco delle opzioni)



1

Se hai TensorFlow 2.x:

sess = tf.compat.v1.Session (config = tf.compat.v1.ConfigProto (log_device_placement = True))


1
Perché fornire una risposta parziale a una domanda 4 y / o che ha già più risposte con un'ottima accettazione? Questo fornisce nuove conoscenze?
— Amitai Irron,

@amitai, tutti i pacchetti e gli strumenti si aggiornano e, nella maggior parte dei casi, gli errori ritornano. Le vecchie soluzioni corrette potrebbero non funzionare oggi.
— Jade Cacho,

0

Un'altra variante, immagino: P

python3 -c 'print(__import__("tensorflow").__version__)'

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.