We will learn how to install TensorFlow and try several ways to install it; then, we will also learn how to install TensorFlow in a separate
conda environment in Python.
Use the Correct Way to Install TensorFlow in Python
TensorFlow does not come automatically with Anaconda distribution, so we have to install it separately. Before installing, if we write the command to import
tensorflow, we will get an error message like the one below.
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
Now we will show you how to install this; you can download the Anaconda distribution from here for Windows 64-bit, and after this download, we need to install that, and the installation instruction is also given in this link.
There are two methods for installing TensorFlow:
- Through the command prompt, we will give this command, and the TensorFlow will be installed.
conda install -c tensorflow-gpu
conda create --name tensorflow python=3.5 activate tensorflow
- Another way to install is to go to Anaconda navigator and click on the environment; then, we will have a based environment that is the root environment. If we want to install TensorFlow, we must create another environment.
We will click on the
Environments tab on the right side, and after opening the
Environments tab, we need to click on the
Create button; then, we need to give a name to the new environment.
It will automatically pick the Python version; otherwise, we can select this via a drop-down and click on the
It will take some time if we go to the new environment, but we can see we have installed all the basic packages. For TensorFlow, we have to select the
Not installed option, and after selecting this option, we need to search “tensorflow” in the search box.
After clicking on the correct module, we click
Apply, and we will also install the
keras library in this TensorFlow environment. It will take some time, and sixty software packages will be installed to run the
If we go there and search for TensorFlow, we will get this; after selecting the new environment, we have to go home and install the Jupyter notebook, then we can launch from here. After installation, we will launch the Jupyter notebook and try to import TensorFlow.
If you get any errors while importing TensorFlow, do not worry; we have another way to install TensorFlow. First, we have to uninstall TensorFlow from the Anaconda environment because it is useless if it does not work.
We need to go back to the Anaconda navigator and find the TensorFlow package and left-double click on it; the
remove option will appear to click on it and apply for this process. After the uninstallation, we need to open the command prompt and run the following command.
pip install tensorflow
After installation, we will run a Jupyter notebook from the local environment because we have installed TensorFlow in the local environment. Now, if we try to import TensorFlow, this time, TensorFlow has been imported, and no error message has been shown.
If any method does not work, follow this link, where you will find other ways to install TensorFlow.
- Can Only Concatenate List (Not Int) to List in Python
- Invalid Syntax in Python
- Value Error Need More Than One Value to Unpack in Python
- ValueError Arrays Must All Be the Same Length in Python
- Fix the TypeError: Object of Type 'Int64' Is Not JSON Serializable
- Fix the TypeError: 'float' Object Cannot Be Interpreted as an Integer in Python