Using TensorFlow with Anaconda

During your work, you will encounter situations where you need multiple versions of TensorFlow on the same machine, such as TensorFlow 1.0 or TensorFlow 1.2. We may need to use TensorFlow with Python 2.7 or 3.0. With the previous installation, we have already successfully installed TensorFlow in the system Python. Now, we will show you how to use Anaconda to have multiple working environments on the same machine. With Anaconda, we can even use different versions of other popular libraries, such as OpenCV, NumPy, and scikit-learn.

First, we need to download and install miniconda from https://conda.io/miniconda.html. In our case, we select Python 2.7 64-bit bash installer, as we want to use Python 2.7 as the default Python. Nevertheless, we can create environments with either Python 2.7 or Python 3 later. We need to run the following command to run the installer:

bash Miniconda3-latest-Linux-x86_64.sh

We need to accept the End User License Agreement:

After that, we can continue the installation. The result should look like this:

Finally, we need to source the .bashrc file to get Anaconda up and running:

source ~/.bashrc

In the source code of this chapter, we have already provided some environment configurations that you can use to create your desired environment.

Here is an environment that uses Python 2.7, OpenCV 3, and TensorFlow 1.2.1 with GPU support. The configuration is named env2.yml:

You can easily change python=2.7 to python=3 and opencv3 to opencv to have Python 3 and OpenCV 2.4 respectively.

Now, let's run the following command to create the environment:

conda env create -f env2.yml

The result should look like following:

Next, you can type source activate env2 to activate the environment.

Finally, we will need to verify TensorFlow, as before:

You may notice the (env2) in the top-left of the preceding image. That shows the name of the current environment. The Python version on the second line is 2.7.13 and is packaged by conda-forge.

Now, you can create several different environments to use in your workflow. Here is an example of an environment named env3 with Python 3 and OpenCV 2.4:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.190.175