Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24369

John Ludhi/nbshare.io: How To Install Python TensorFlow On Centos 8

$
0
0

How To Install Python TensorFlow On Centos 8

Make sure you have Python 3.5+ installed on your system.

In [ ]:
python--versionPython3.6.8

Let us first update the system

sudo yum update

Install Tensorflow With Gpu

Install Cuda

In [ ]:
https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda-repo-rhel8-11-0-local-11.0.3_450.51.06-1.x86_64.rpmsudorpm-icuda-repo-rhel8-11-0-local-11.0.3_450.51.06-1.x86_64.rpmsudoyum-yinstallcuda

Depending upon where the libraries get installed, you might run in to following error, when you import tensorflow.

Could not load dynamic library 'libcuda.so.1';

Do following...

cp -p /usr/lib64/libcuda.so.1 /usr/lib/

Install libcudart

In [ ]:
wgethttps://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/cauldron/x86_64/media/nonfree/release/nvidia-cuda-toolkit-devel-11.2.0-8.mga8.nonfree.x86_64.rpmsudorpm-invidia-cuda-toolkit-11.2.0-8.mga8.nonfree.x86_64.rpmsudoyuminstallnvidia-cuda-toolkit

Now let us install tensorflow using pip.

In [ ]:
pipinstalltensorflow

Test Tensorflow

Launch Ipython or Python shell and try out these commands.

In [ ]:
In[1]:importtensorflowastf2021-07-0321:00:42.953020:Itensorflow/stream_executor/platform/default/dso_loader.cc:53]Successfullyopeneddynamiclibrarylibcudart.so.11.0In[2]:withtf.compat.v1.Session()assess:...:hello=tf.constant('hello world')...:print(sess.run(hello))...:2021-07-0321:00:48.919579:Itensorflow/stream_executor/platform/default/dso_loader.cc:53]Successfullyopeneddynamiclibrarylibcuda.so.12021-07-0321:00:48.934110:Etensorflow/stream_executor/cuda/cuda_driver.cc:328]failedcalltocuInit:CUDA_ERROR_NO_DEVICE:noCUDA-capabledeviceisdetected2021-07-0321:00:48.934146:Itensorflow/stream_executor/cuda/cuda_diagnostics.cc:156]kerneldriverdoesnotappeartoberunningonthishost(ns3273416.ip-5-39-70.eu):/proc/driver/nvidia/versiondoesnotexist2021-07-0321:00:48.936834:Itensorflow/core/platform/profile_utils/cpu_utils.cc:114]CPUFrequency:3700210000Hzb'hello world'

If you notice above, there is an error "CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected". I am getting this error because machine has no GPU.

To avoid the above error, make sure you do the following setting.

In [ ]:
importosos.environ['CUDA_VISIBLE_DEVICES']="0"

Common errors

You might run in to following Tensorflow error while importing "Keras"

Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow?

Make sure you have Python 3.5+ installed. Then follow the above instructions to install Tensorflow.


Viewing all articles
Browse latest Browse all 24369

Trending Articles