Friday, November 12, 2021

DaVinci Resolve Scripting Setup - ModuleNotFoundError: No module named 'DaVinciResolveScript'


While working on a project, I had the opportunity to do some coding in Blackmagic's DaVinci Resolve. Resolve supports python 2.7 and python 3.6. Jumping in, I opened and read their documentation on how to get a basic script running. 

First, I added the environment variables to my computer as they listed them: 

RESOLVE_SCRIPT_API="%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting"
RESOLVE_SCRIPT_LIB="C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll"

I created a new script ( based on their example and placed it in my Utility folder so that it would show up in the application (C:\ProgramData\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Utility). 

#!/usr/bin/env python
import DaVinciResolveScript as dvr_script
resolve = dvr_script.scriptapp("Resolve")
projectManager = resolve.GetProjectManager()
projectManager.CreateProject("Hello World")

After restarting Resolve, the link displayed fine. 

Once clicked, however, nothing would happen. I opened the Console (from the same Workspace menu) and saw this: ModuleNotFoundError: No module named 'DaVinciResolveScript'

There seems to be a lot of conversation with people having this issue in forums, but very few people with solutions which is why I created this post. 


In order to determine what went wrong, we need to start by looking at what python is has available to it and make sure it matches our expectation. To do this, we are going to open PowerShell and launch the python interpreter. Once we see the python input prompt (>>>) we can use sys to see what our path resolutions are for python dependencies. 

import sys
print (sys.path)

The python interpreter printed out several paths include: 

['', 'C:\\Users\\MUser\\%PYTHONPATH%', 'C:\\Users\\MUser\\%RESOLVE_SCRIPT_API%\\Modules', 'C:\\Python27\\', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']

Looking over this list, I realized python was trying to resolve full paths as being relative from my current directory. (I don't know why exactly so comment if you know). If you look at the environment variables we listed above, you will see what the full paths of these variables in supposed to be. 

Next, I went back to the Console inside Resolve and repeated the code to import and print sys.path. Resolve indicated to me the same thing, but with paths relative to it's operating directory. 

C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\%RESOLVE_SCRIPT_API%\\Modules

This explains why DaVinciResolveScript could not be found. To fix this problem for the moment, I decided to use a full path for my PYTHONPATH environment variable and this has for the moment seemed to resolve the problem. 

C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\Modules

This resolved python finding the right files. Finally, all I needed to do was enable External scripting using Local under Resolve Preferences.

If additional solutions are required, I will try to update this post with that information. 

Good luck!

No comments: