TensorFlow is a very powerful Open Source Deep Learning environment.
To use TensorFlow is just a little more complicated than other Python libraries, as it may conflict with other versions of libraries present. In order to avoid potential conflicts we set up a ‘virtual environment’. That environment will hold a version of Python that is compatible with TensorFlow itself, and other packages like NumPy, Pandas, and MatPlotLib.
First open up a terminal or command line environment. And install the TensorFlow environment with the following line.
conda create -n tensorflow_env tensorflow
The Anaconda TensorFlow environment does not access Python/Anaconda packages you have installed elsewhere. Though it installs NumPy, three other common packages need separate installation.
We are going to ‘activate’ the TensorFlow environment, install some packages, and then deactivate the environment.
conda activate tensorflow_env
You should now see (tensorflow_env) at the start of the command line. Now install these commonly used packages, with:
conda install -n tensorflow_env scikit-learn pandas matplotlib
Then deactivate the environment with:
If you are comfortable using the terminal then you may use TensorFlow directly from there by using conda activate tensorflow_env to activate the environment and deactivate to end the session.
But you may also use Anaconda Navigator. Open up Anaconda Navigator. Click on ‘environments’, and select ‘tensorflow_env’ (here is where you can switch back to your ‘normal’ environment by selecting ‘base (root)’.
Now click back on ‘Home’. If you use Visual Studio code for editing and running code you can launch directly here. If you use Spyder you will see that you need to install Spyder into this environment first.
That’s it! Launch your code editor of choice, and you should now be able to import TensorFlow as with any other package. The normal convention is:
import tensorflow as tf