2020, Installing TensorFlow 2.0, Keras, & Python 3.7 in Windows 10

Let’s install tensorflow 2.0 for Windows
using the CPU. If you’re interested installing this for the Macintosh or for
Windows with a GPU that’s a different video, I have links below. Hi this is Jeff
Heaton welcome to Applications of Deep Neural Networks with Washington
University. To see all my videos about Kaggle, neural networks, and other AI
topics click the subscribe button and the bell next to it and select all to be
notified of every new video. We are starting with a fresh install of Windows
10, this makes sure that everything works and it is not dependent on anything that I
might have done previously. I have all the windows updates installed as of late
December 2019. Each semester that I teach this course I go through Windows
installs with my students. There’s usually over 80 of them, and believe me I
know most things that can go wrong with installing TensorFlow for Keras and
Windows. I will try to point these out as I go through, but feel free to step past
some of my descriptions of the errors. I do have a link to all the parts of this
video in the description so you can easily jump to the timestamps for each
of these. Now I do monitor the comments on this video closely, so if you run into
any thing, feel free to post them there. Also, search Google, because believe me
there’s all kinds of information on Stack Overflow about the kinds of errors
that you probably run into doing this sort of thing. The entire installation
process for Windows takes about 30 minutes for me to complete. You can see
this by looking at the clock below. I’m starting at about 7:15. To keep the video
short I will fast-forward through the points where the computer makes me wait
for things. You can see all the steps listed here. I also have an “about the
environmental script setup.” There’s a script that I provide to you and I
describe just kind of how that captures some of the installation processes. I
will update this script as the semester goes forward, as TensorFlow makes changes
that require some changes to this process.
I’ll only rerecord the video if the process has changed substantially to the
point that I can no longer just change the install script. This installs
both TensorFlow for the command line and also for Jupyter notebooks. At this
point you’re ready to hook it up to an IDE, if you choose. To do one of those I
do have a separate video for PyCharm. Step one, we’re going to download
MiniConda. Use Chrome or whatever your favorite browser happens to be. So go
ahead and search for the MiniConda installation. For Python, MiniConda is
just the minimal version of the Anaconda Python environment, and all of these
basically have the mathematical and artificial intelligence packages that
you typically need already installed. You still have to install TensorFlow on top
of it though. It’s critical that you choose a 64-bit version of Python, 32
bits is just not supported with TensorFlow.
Also, use whatever the latest version you see 3.7 here, if the latest version
becomes 3.8 or later, install that. We’re going to later create a virtual
environment that has whatever version of Python TensorFlow is currently needing.
Step 2 let’s install MiniConda. Ok, run the executable that you downloaded. Click
Next to get onto the License Agreement. Also, accept the License Agreement.
Install it for “just me,” this tends to get you fewer security prompts later. This is
the path that I really do prefer sometimes it’ll try to put it under “app
data.” This is controversial, but I do like to check both of these. If you’re going
to set it as the default one on the bottom one, you might as well put it as
the top as well. This will just cause fewer things to not find it, if you don’t
click that first check. Now install it. We’re fast-forwarding through this part
because this does take awhile. MiniConda is installed. Most of the
time things do not go wrong at this point. Now we’re going to download an
Anaconda YAML script that I created to do most of the installation for you.
Just do a search on “github Jeff Heaton” That’ll take you to my GitHub
repository. You can see it here. It’s a very cool repository!! So, definitely
follow me, click to star-me. Go to this repository, though. This has the file that
you want, and scroll down and find tensorflow.yml.
This is the script that you will actually make use of, so click the
TensorFlow YAML file to open it, and then click on RAW, so that you see it
just as pure text. Now right-click and save this to a directory on your machine,
where you can easily find it later. Here I’m just storing it right to my
user directory. Okay, now it’s saved we’ll use this in the next step. Before we
continue let’s have a look at this file and see what’s all packed into here. Now
this may look different because I will update this. This is the name of the
virtual environment that you’re creating. So, this can be a completely different
version of Python and everything under your main install. These are the
dependencies. This is what you’re actually installing into there. Notice I
am putting in Python 3.7. If later versions of TensorFlow support newer
versions (and they don’t always do that right up front) I will update that. I’ll
move that to 3.8 as soon as I’m able to. These are the other packages and if
their version dependent I will put a double equals on there, or single equals
actually in this case, and lock them to something.
There’s also PIP installs, the ones at the top are CONDA installs and PIP
installs are just two different ways of installing things. Ok, step four now we’re
going to install Jupyter, you need to launch this. Now I hate the ads in here.
Some people say that guy looks like me. I really don’t see it. But let’s go-ahead
and start up a terminal prompt command prompt, as they’re called in Windows. The
first thing we’re going to do is rename that TensorFlow YAML file. Windows
downloaded that as a text file, a YAML text file, I really hate that feature of
Windows. So, we just need to rename it so that it’s not a text file, won’t work
that’s a YAML file. So, we can now make use of it and now we’re gonna kinda
install Jupyter. Jupyter is a nice, sort of browser-based IDE, that lets you mix a
variety of things. We’re fast-forwarding this part of it,
because it does take a while to install. Jupyter will use Jupiter for the initial
tests even if you plan to use mostly an IDE I recommend having Jupiter up and
ready to go. Okay, Jupyter is done. So, now we are going to run that installation
script that we downloaded. The YAML file. Now make sure that it’s .YML. If
windows appended a .txt on to the end, then rename it like we did earlier. Now I am
going to run the command that creates the environment the. This creates a
sub-environment underneath our main one. I like to do everything in sub-environments and leave my main environment very clean. Now windows
violates this unfortunately, you can’t in Windows create a pure separate
environment like you can in Linux and Mac and there’s some ramifications to
this and we’re going to talk about this. This is one of the common things that
will go wrong. So now we are in the process of creating this environment.
This will take a little while. Now, also the command that I executed. Don’t try
to type that from what I typed up there I will put a copy of that in the
description below of this video that way in case it changes any I can make minor
tweaks there. All right, now we can do a quick test. If anything went wrong there
then definitely Google your error message or post a comment. Now I can
start a Python you’ll see that I’m in Python I’m gonna “import tensorflow
as tf” Now this is not going to work. See, there’s no module name TensorFlow. I’m
still out in my main Python environment. I need to quit out of here and do “conda
activate tensorflow” This moves me into that environment that I meant, if you’re
not if you’re trying to import tensorflow and it’s just saying that
it’s not there, you’re usually not in the environment that you created for it, or
you somehow did not install tensorflow. Now I am in the correct environment. You
are able to see from the prompt, I’m in tensorflow and I “import tensorflow as tf”
This takes a moment, but the fact that it’s pausing is good that means that it
worked. Ok now I’m going to print out the version of it just a double check it.
print tf dot version, now you might have gotten some errors there instead.
Definitely Google those or post them in the comments. Probably Google them first.
And now let me show you some of the other things that can go wrong. When you
try it this is a very important step make sure you complete it, that long
command that I’m typing there is in the description of this video. So just copy
and paste it from there. This registers that environment that you
just created into Jupyter, so the Jupyter can find your new kernel. If you skip
this step Jupyter won’t see your kernel and
nothing will work inside of Jupyter. Ok, now everything is installed.
Step 8, let’s test Jupyter and talk about some of the things that can go wrong. So
make sure that you’re in that “tensorflow” environment. if not “conda activate” it
and we’re going to start up Jupyter notebook. If you run this for the first
time, it’ll ask you what browser you want. I’m going to use Chrome. I hate that
Microsoft keeps adding on edges and corners and Internet Explorer’s and
other browsers that I don’t want to use. But pick chrome. Okay this is Jupiter
we’re going to go up to this new and create one notice python 3 and 3.7
TensorFlow. If you don’t see that 3 7 TensorFlow, or whatever you named it, then
you probably skipped the kernel install step that I told you about, and you’ll
always see it up there. You can also change kernel here at run time, that
doesn’t work as nice as it should on Windows, and we’ll see that in a moment.
But let’s go ahead and “import tensorflow as tf” That will show you that it’s there
and we can print out the version. Let’s go ahead and run that. It takes a moment.
That shows that it’s working. 2.0 perfect! You’re seeing that you’re basically done.
But you may want to listen to this next gotcha
in Windows. So let me exit that. I’m going to exit the command prompt and now
startup like it’s done. I’ve had many students do this where it worked fine,
when they were standing in front of me and then they go home and try and it
doesn’t work. So let’s launch a command prompt and let’s forget to “conda
activate tensorflow” we’re just going straight into Jupyter notebook. We start
it up and now we’re going to create a new notebook actually let’s open up the
old one that we had before. Now this notebook is already pointing to the
correct kernel it’s pointing to “TensorFlow
Python 3.7” and if we were on a Mac or UNIX machine this will work just fine. But
in Windows you have to specify the kernel both in Jupiter and at the
command prompt before you start it. Otherwise you will get errors now here
we’re seeing the TensorFlow is not there that’s because we have the wrong kernel
it didn’t save our kernel from before so we select our kernel. On the other
operating systems you’d be fine you would have still gotten that error on
the other OSs. But in Windows you run this and you
get this dreaded “DLL error” Go look at the comments and some of my old videos
were set up DLL error just plagues you in windows.
So let’s go ahead and look at what’s really going on here. This is where we’ve
installed it too this is my base Python environment, but then I go into the
MiniConda 3 and this is the base this is the base install. If you go into a
directory in here called envs that shows you the sub environments that
you’ve created for this, and unfortunately DLL’s tend to bleed
through. So even though you’ve created this virtual environment, it’s not as
pure as it is in other operating systems. What you’ve got to do is get completely
out of this and make sure that Jupyter was started in that environment. You
can’t just dynamically switch environments like that, at least at this
point in Windows, with Anaconda I found this to cause all sorts of errors. Just
make sure that you actually start up a command prompt. Do “conda activate
tensorflow” before Jupyter. Now you see from the
prompt you’ve switched into that environment and now you start up Jupyter notebook. Nothing’s will be happier. Let’s open up our notebook
there’s that ugly error from before. Now it’ll be fixed because having that main
environment or that main DOS prompt that we started from switched out to that
environment allows those DLLs to be in the path and now they’re going to be
found. Pauses are good here because that means it’s working. Now that’s a typo I
can’t spell version. 2.0. Perfect so always make sure you do that extra step
when you’re dealing with Windows. Let me show you another shortcut that you can
potentially do that they do to make this a little easier. You can run Jupyter
notebook for that environment right from the command prompt and that
saves you having to activate it. That does those steps automatically for you.
So now we’ve launched it from the Start Prompt, we open that same notebook and it should work just fine. Anaconda also gives you something called an “Anaconda
Prompt” I tend to not use that because I often put Python into the actual path
the check box that we saw during the install. Okay there we are
2.0 so either launch Jupyter from the “Start Menu” like I just showed you or
make sure to activate first. Ok you should have an environment all set up
and ready to go. If you ran into some problems then definitely post a comment
or Google to try to find your answer. Thank you for watching this video and if
you find this kind of thing interesting, please subscribe to my YouTube channel.

7 thoughts on “2020, Installing TensorFlow 2.0, Keras, & Python 3.7 in Windows 10

  1. i just import tensorflow and below error came.
    i followed you as it is.

    import tensorflow as tf

    OSError Traceback (most recent call last)
    <ipython-input-1-64156d691fe5> in <module>
    —-> 1 import tensorflow as tf

    ~AppDataRoamingPythonPython37site-packagestensorflow__init__.py in <module>
    38 import sys as _sys
    —> 40 from tensorflow.python.tools import module_util as _module_util
    42 from tensorflow._api.v2 import audio

    ~AppDataRoamingPythonPython37site-packagestensorflowpython__init__.py in <module>
    45 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
    —> 47 import numpy as np
    49 from tensorflow.python import pywrap_tensorflow

    ~AppDataRoamingPythonPython37site-packagesnumpy__init__.py in <module>
    139 # Allow distributors to run custom init code
    –> 140 from . import _distributor_init
    142 from . import core

    ~AppDataRoamingPythonPython37site-packagesnumpy_distributor_init.py in <module>
    24 # NOTE: would it change behavior to load ALL
    25 # DLLs at this path vs. the name restriction?
    —> 26 WinDLL(os.path.abspath(filename))
    27 DLL_filenames.append(filename)
    28 if len(DLL_filenames) > 1:

    ~.condaenvstf_mllibctypes__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    363 if handle is None:
    –> 364 self._handle = _dlopen(self._name, mode)
    365 else:
    366 self._handle = handle

    OSError: [WinError 193] %1 is not a valid Win32 application

Leave a Reply

Your email address will not be published. Required fields are marked *