Reputation: 18617
I am trying to differentiate within python whether a user has installed tensorflow-gpu
or just tensorflow
(on the CPU, which lacks GPU support).
I do not want to have to run a trivial model (with log_device_placement
) to have to figure that out.
I have tried making use of tensorflow.__version__
, but it seems like 1.3.0-rc2
is printed both ways.
Upvotes: 2
Views: 4618
Reputation: 68728
Answer by Mohamed isn't working anymore in Python 3.6+ but below does work:
import pkg_resources
l = [d for d in pkg_resources.working_set if 'tensorflow' in str(d)]
print(l)
Upvotes: 0
Reputation: 14689
Run pip freeze | grep tensorflow
if it's installed you will see tensorflow-gpu
in the results.
If you want to check it programmatically within python, this is one way to go:
import pip
l = next(str(i) for i in pip.get_installed_distributions() if 'tensorflow-gpu' in str(i))
print(l)
which outputs in my case:
tensorflow-gpu 0.12.0rc0
Upvotes: 2
Reputation: 1836
Was it installed via pip? You could check pip list
and it will show either:
tensorflow-gpu
or
tensorflow
the second is the cpu version
Upvotes: 4