How To Install Python TensorFlow On Centos 8
Make sure you have Python 3.5+ installed on your system.
python --version
Python 3.6.8
Let us first update the system
sudo yum update
Install Tensorflow With Gpu
Install Cuda
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.rpm
sudo rpm -i cuda-repo-rhel8-11-0-local-11.0.3_450.51.06-1.x86_64.rpm
sudo yum -y install cuda
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
wget https://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.rpm
sudo rpm -i nvidia-cuda-toolkit-11.2.0-8.mga8.nonfree.x86_64.rpm
sudo yum install nvidia-cuda-toolkit
Now let us install tensorflow using pip.
pip install tensorflow
Test Tensorflow
Launch Ipython or Python shell and try out these commands.
In [1]: import tensorflow as tf
2021-07-03 21:00:42.953020: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
In [2]: with tf.compat.v1.Session() as sess:
...: hello = tf.constant('hello world')
...: print(sess.run(hello))
...:
2021-07-03 21:00:48.919579: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcuda.so.1
2021-07-03 21:00:48.934110: E tensorflow/stream_executor/cuda/cuda_driver.cc:328] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2021-07-03 21:00:48.934146: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (ns3273416.ip-5-39-70.eu): /proc/driver/nvidia/version does not exist
2021-07-03 21:00:48.936834: I tensorflow/core/platform/profile_utils/cpu_utils.cc:114] CPU Frequency: 3700210000 Hz
b'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.
import os
os.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.
from Planet Python
via read more
No comments:
Post a Comment