Install Tensorflow/Keras in WSL2 for Applications of Deep Neural Networks
Deep learning has become a powerful tool in the field of artificial intelligence, and Tensorflow and Keras are two of the most popular libraries for building and training deep neural networks. If you’re using Windows Subsystem for Linux 2 (WSL2) and want to take advantage of these libraries, you’ll need to install them within your WSL2 environment. In this article, we’ll walk you through the process of installing Tensorflow and Keras in WSL2 for your deep learning applications.
Step 1: Set Up WSL2
If you haven’t already set up WSL2 on your Windows machine, you’ll need to do so before you can install Tensorflow and Keras. Follow the instructions provided by Microsoft to enable WSL2 on your system.
Step 2: Install Python and Pip
Once you have WSL2 up and running, open the terminal and install Python and Pip by running the following commands:
sudo apt update
sudo apt install python3 python3-pip
Step 3: Install Tensorflow and Keras
Now that Python and Pip are installed, you can use Pip to install Tensorflow and Keras. Run the following commands in the terminal:
pip install tensorflow
pip install keras
These commands will download and install the latest versions of Tensorflow and Keras in your WSL2 environment.
Step 4: Verify Your Installation
To ensure that Tensorflow and Keras have been installed correctly, you can create a simple Python script to test them. Use your favorite text editor to create a file called test_tensorflow.py
with the following contents:
import tensorflow as tf
import keras
print(tf.__version__)
print(keras.__version__)
Save the file and run it in the terminal with the command python test_tensorflow.py
. If everything is set up correctly, you should see the versions of Tensorflow and Keras printed to the console.
Conclusion
With Tensorflow and Keras installed in your WSL2 environment, you’re now ready to start building and training deep neural networks for your applications. These libraries provide a wealth of tools and utilities for working with complex neural networks, and WSL2 allows you to take advantage of their power from within your Windows environment. Happy coding!
OMG After a whole night of struggling, I finally now can work with TensorFlow GPU! thank you so much
how to import an auther packages with wls????
You can set the environment variable TF_CPP_MIN_LOG_LEVEL=2 to get those tensorflow warning to go away.
is No NUma support is fine?
Excellent explanation, Thank you for the effort taken to publish this information.
i am getting error while installing opencv using this command in jupyter notebook : pip install opencv-python
ImportError: libGL.so.1: cannot open shared object file: No such file or director
Please help me to resolve. thanks.
can anyone tell me how to specify file path in wsl
I had originally written this
dataset = tf.keras.preprocessing.image_dataset_from_directory(
"\Image Data base",
seed=123,
shuffle=True,
image_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE
)
but I get directory not found everytime I try to run it
and my python kernel kind of keeps crashing every few minutes
Conda installed python 3.11 and I am getting the following error. Jeff, do you have any suggestion?
Pip subprocess error:
ERROR: Could not find a version that satisfies the requirement tensorflow==2.11.0 (from versions: 2.12.0rc0, 2.12.0rc1)
ERROR: No matching distribution found for tensorflow==2.11.0
Hi Jeff, on my side conda installed python 3.11 as latest by default. Maybe set also python=3.9 in the conda create to be sure its the right version
Fantastic Tutorial. Thank you from Italy
Wow wsl2 has been such a pain to get setup! Had to use older 11.7.1 cuda drivers to get gpus to work when running docker containers
Does anyone know if you can still use screen capture packages within WSL2?
Lets say a screen capture package requires DirectX-whatever: it would not work as python will think it's on a Linux host. Correct?
Thanks Jeff
Thank you so much , Jeff!!! I'm glad that you hear your audience!!! 👏👏👏
thank you Jeff for the knowledge you share.
It's okay.