Install OnxxRuntime on Windows

Ashley Tharp
Mar 24 · 3 min read

Video Version: https://youtu.be/Tiq_vea5Eqg

If you’re running into this error when using OnnxRuntime in Python, it’s because you’re missing a Cuda dependency or something,

ImportError: cannot import name 'get_all_providers' from 'onnxruntime.capi._pybind_state

The OnnxRuntime doesn’t make it super explicit, but to run OnnxRuntime on the GPu you need to have already installed the Cuda Toolkit and the CuDNN library.

First check your machine and make sure you have a Cuda Enabled Card. If you have a pretty recent NVIDIA card you are probably good, but go to the NVIDIA website and check the compatibility tables and make sure if needed.

The Windows Device Manager can be opened via the following steps:
Open a run window from the Start Menu
Run:

control /name Microsoft.DeviceManager

Check under display adaptors to see your card

First install the Cuda Toolkit:

It opens a Window that looks like this:

C:\Users\USERNAME\AppData\Local\Temp\CUDA

Verify your installation on the command line:

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Feb_14_22:08:44_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.2, V11.2.152
Build cuda_11.2.r11.2/compiler.29618528_0

Now Install cuDNN 8.0.2.39

https://developer.nvidia.com/rdp/cudnn-download
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-windows

Download the zip and extract it

Copy the following files into the CUDA Toolkit directory.

copy cuda\bin\cudnn*.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.x\bin.
Copy cuda\include\cudnn*.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.x\include.
Copy cuda\lib\x64\cudnn*.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.x\lib\x64.

ok, now with all the prereqs out of the way you can do:

pip install onnxruntime
pip install onnxruntime-gpu

Geek Culture

Proud to geek out.

Sign up for Geek Culture Hits

By Geek Culture

Subscribe to receive top 10 most read stories of Geek Culture — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Ashley Tharp

Written by

Research and Development | Dev Ops | Software Engineer | Topaz Labs

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Ashley Tharp

Written by

Research and Development | Dev Ops | Software Engineer | Topaz Labs

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store