Puget Systems print logo
Read this article at https://www.pugetsystems.com/guides/1520
Dr Donald Kinghorn (Scientific Computing Advisor )

Install TensorFlow 2 beta1 (GPU) on Windows 10 and Linux with Anaconda Python (no CUDA install needed)

Written on June 26, 2019 by Dr Donald Kinghorn


TensorFlow 2.0.0-beta1 is available now and ready for testing. What if you want to try it but don't want to mess with doing an NVIDIA CUDA install on your system. The official TensorFlow install documentations has you do that, but it's really not necessary.

What I will present in this post will give you a simple way to setup TensorFlow 2.0.0-beta1 on Windows 10 or Linux. It's essentially the same in both OS's.

The basic idea

I'm using Anaconda Python which has largely become "the" standard Python distribution for data-science, ML/AI and scientific computing. It's not perfect but it's nicely done. Your opinion may differ and I understand reasons for that, but I still find it pretty easy to recommend Anaconda Python.

Installing TensorFlow with GPU support using Anaconda Python is as simple as creating an "env" for it and then a simple install command.

conda create --name tf-gpu
conda activate tf-gpu
conda install tensorflow-gpu

That gives you a full install including the needed CUDA and cuDNN libraries all nicely contained in that env.

I was looking at the install documentation for the TensorFlow 2.0.0-beta1 and saw that it was still being built with links to CUDA 10.0 and cuDNN 7.x. That is the same dependencies as TensorFlow-GPU 1.13.1 Which is the current (official) packaged version on Anaconda cloud. [Version 1.14 is now available in the CPU package and the GPU version will likely update to this soon too. I assume the CUDA dependencies will remain the same for the time being but please do check that!]

We will use the TensorFlow 1.13.1 env as a base for the install of TensorFlow 2.0.0-beta1 i.e. we'll do TensorFlow-gpu install with "conda" and then a "pip" install of TensorFlow 2.0.0-beta1. Easy!

Install Anaconda Python and tensorflow-gpu

I'm going to refer you to some recent posts for doing this.

For Windows 10 look at How to Install TensorFlow with GPU Support on Windows 10 (Without Installing CUDA) UPDATED!. That post is very detailed and should get you up and running with Anaconda Python and the current version of TensorFlow with CUDA GPU support. I recommend that Linux users take a look at this post too since it is up-to-date and has general information in it.

An older post that is still relevant for Linux users is, Install TensorFlow with GPU Support the Easy Way on Ubuntu 18.04 (without installing CUDA). This post is a over a year old now but still mostly OK. I have some updated notes in it. Really, it's pretty straight forward getting Anaconda Python installed on Linux and the information in the Windows 10 post is pertinent as well, read that even if you are using Linux.

This is pretty straight forward and those guides above will walk you thought it if needed. Download the Anaconda installer, run it, accepting defaults and add the optional "PATH" setup. Then look at the Windows 10 post mentioned above to see how to update everything, setup an "env", install TensorFlow-GPU 1.13.1 and setup things for Jupyter notebook. Then test that to make sure everything is working OK.

Clone your TensorFlow-GPU 1.13 (or .14) env and "pip" install TensorFlow-GPU 2.0.0-beta1

I am assuming you have have a working TensorFlow-GPU 1.13(or .14) working and installed in an env named "tf-gpu".

Clone the existing tf-cpu env and call it tf-gpu-2beta1,

conda create --name tf-gpu-2beta1 --clone tf-gpu

Next activate the new env and use "pip" in that conda environment to instal the new TensorFlow-GPU 2.0.0-beta1

conda activate tf-gpu-2beta1
pip install tensorflow-gpu==2.0.0-beta1

You now have a base with most of the dependencies including CUDA from the original TensorFlow-GPU install and pip will pull down the new TensorFlow 2.0.0-beta1 package along with any other dependencies that were not already present. The old TensorFlow will still be in the env but when you "import tensorflow" you get the newest version in the env, which will be 2.0.0-beta1.

That's it! You now have the first beta of TensorFlow 2.0 installed with CUDA support for your NVIDIA GPU.

To create a Jupyter kernel for that new env you ca do this,

make sure ipykernel and Jupyter are installed (assuming you still have tf-gpu-2beta1 activated)

conda install ipykernel jupyter

create the kernel for Jupyter notebooks

python -m ipykernel install --user --name tf-gpu-2beta1 --display-name "TensorFlow-GPU-2.0-beta1"

A quick test

First you can list the packages in your "activated" tf-gpu-2beta1 env,

conda list

Along with a lot of other packages you will see,

cudatoolkit 10.0.130 0
cudnn 7.6.0 cuda10.0_0
tensorflow-gpu 2.0.0b1 pypi_0 pypi

A quick test from the command line (I'm using Powershell on Windows 10 right now to check this on my laptop as I write this post.)

With tf-gpu-2beta1 still activated the following will print out a constant "Hello tf.__version__" using eger execution which is default in TensorFlow 2.


import tensorflow as tf

print( tf.constant( 'Hellow from TensorFlow ' + tf.__version__ ) )

Here's what that Powershell session looks like including the output that shows my active NVIDA GTX1060 GPU on this laptop and the TensorFlow version.

PS>conda activate tf-gpu-2beta1

Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
>>> print( tf.constant( 'Hellow from TensorFlow ' + tf.__version__ ) )

2019-06-25 16:39:58.943121: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll

2019-06-25 16:39:59.805979: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: name: GeForce GTX 1060 with Max-Q Design major: 6 minor: 1 memoryClockRate(GHz): 1.3415 pciBusID: 0000:01:00.0

2019-06-25 16:39:59.814565: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.

2019-06-25 16:39:59.819875: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0 2019-06-25 16:39:59.824079: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

2019-06-25 16:39:59.831704: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: name: GeForce GTX 1060 with Max-Q Design major: 6 minor: 1 memoryClockRate(GHz): 1.3415 pciBusID: 0000:01:00.0

2019-06-25 16:39:59.838581: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.

2019-06-25 16:39:59.844679: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0 2019-06-25 16:40:00.773606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:

2019-06-25 16:40:00.779446: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0
2019-06-25 16:40:00.782123: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N

2019-06-25 16:40:00.786023: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4712 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 with Max-Q Design, pci bus id: 0000:01:00.0, compute capability: 6.1)

tf.Tensor(b'Hellow from TensorFlow 2.0.0-beta1', shape=(), dtype=string)

Have fun trying TensorFlow 2 beta1 with GPU support. This is a major update to TensorFlow and it looks like it will be great!

Happy Computing! --dbk @dbkinghorn

Why Choose Puget Systems?

Built specifically for you

Rather than getting a generic workstation, our systems are designed around your unique workflow and are optimized for the work you do every day.

Fast Build Times

By keeping inventory of our most popular parts, and maintaining a short supply line to parts we need, we are able to offer an industry leading ship time.

We're Here, Give Us a Call!

We make sure our representatives are as accessible as possible, by phone and email. At Puget Systems, you can actually talk to a real person!

Lifetime Support/Labor Warranty

Even when your parts warranty expires, we continue to answer your questions and even fix your computer with no labor costs.

Click here for even more reasons!

Puget Systems Hardware Partners

Tags: Tensorflow 2, GPU, CUDA, Anaconda Python, Machine Learning
Amir Hossein

Just for future readers if you have tensorflow-gpu=1.14 in your base env it won't work because the installed cuda version is 10.1 (not 10.0 mentioned in this instruction). You should explicitly install the 1.13 version of tensorflow in your base env: `conda install tensorflow-gpu=1.13`

Posted on 2019-07-31 20:10:47
Donald Kinghorn

Sorry I'm late with a reply ... Yes, You have to careful with this in general, version changes can be a problem. The biggest danger when you are using CUDA is having an install on your local system that is in you global PATH that interferes with other package version dependencies. This is the main argument for using Anaconda with a specific env

If in an activated env (say tf-gpu) you do

conda install tensorflow-gpu

you will get the latest Anaconda packaged version along with the correct version of CUDA ad cuDNN for that build. You do not need/want a local CUDA install. In fact a local install can cause trouble.

A great thing about using conda is that you can specify version numbers like =1.14 etc. If things ever get messed up you can install version specific releases.
It's also really easy to just blow away an env and start over! ... and you can always check installed package versions in and activated env with conda list to make sure everything is as you expect (or want)

But yes, version collisions have been a bane of my existence :-)

Posted on 2019-09-06 16:58:32
Amir Hossein

Thank you Donald for your thorough explanation.

Posted on 2019-09-06 17:50:01

Is this working on Ubuntu 18.04? For some reason it is throwing dlerrors ("Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory" etc..) and this is also true of Tensorflow 1.13 and 1.14 installed with conda.

Is there an issue with this conda-only install method when you have a separate local CUDA installation, as I do? When I have my LD_LIBRARY_PATH environment variable set it looks in there (and also throws an error because of a version mismatch) but it seems to just skip all the CUDA packages installed by conda in my actual conda environment..

Posted on 2019-09-23 00:16:47
Donald Kinghorn

It works with 18.04 ...

Yes, there can be PATH problems with a local CUDA install. Let me check something ... OK, in my TF 2 conda env there is a cudatoolkit 10.0 listed. If you have installed a recent CUDA directly then you likely have 10.1 and that is not going to work if those libs show up first.

I recommend removing your CUDA directory from system paths and just setting it with a script when you need it. If you have your CUDA paths set in .bashrc or something then just move them to a separate script file so they aren't autoloaded...

You conda environments will be isolated but system or personal paths will take priority over the env paths when the cuda-runtime goes looking for the tookit and cudnn libs (cuda-runtime is part of the display driver not the toolkit ).

To see what I'm talking about for a CUDA environment look at this cuda install post (it's about 19.04 but it's really the same for 18.04 ... it uses 18.04 repos)

In Step 6) I talk a bit about CUDA environment variable options \

I hope this helps geting everything working for you! --Don

Posted on 2019-09-23 16:44:45

Thanks, I was able to get it working. I think the order of installation matters.

Any idea why Google instructs the user to actually install and use the CUDA toolkit locally? I guess maybe they just aren't Anaconda proponents because it's not their company.

Posted on 2019-09-24 21:39:31
Donald Kinghorn

that seems like as reasonable guess as any :-)

Posted on 2019-09-25 02:21:00

I'm a little confused -- when installing tensorflow-gpu (1.13) in anaconda, it installs all these tensorflow packages:

tensorflow 1.13.1 gpu_py37hc158e3b_0
tensorflow-base 1.13.1 gpu_py37h8d69cac_0
tensorflow-estimator 1.13.0 py_0
tensorflow-gpu 1.13.1 h0d30ee6_0

So then when doing pip install tensorflow-gpu==2.0.0-beta1 it replace only the tensorflow-gpu but leaves the other 1.13 versions. Is this correct?

Posted on 2019-09-24 23:10:21