How to set up external Python in 2023?

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

JeanCall

  • Posts: 12
  • Joined: Tue Dec 19, 2023 3:38 pm
  • Real Name: Jean Callisti

How to set up external Python in 2023?

PostWed Dec 20, 2023 10:19 pm

(DaVinciResolve 18.6.2)

Hello,

i am confused with the proper way of running Python scripts externally (i.e. not from the Py3 console inside DaVinci Resolve). On Windows.

I followed the following flow:

1) Check that all required env variables are set :

Either in Windows command-line syntax, like this, in a .bat file just before executing the python script:
Code: Select all
RESOLVE_SCRIPT_API="%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\"
RESOLVE_SCRIPT_LIB="C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll"
PYTHONPATH="%PYTHONPATH%;%RESOLVE_SCRIPT_API%\Modules\"


...Or directly in Python from within the script
Code: Select all
Not detailed here


Because I'm paranoid (and out of desperation), I also add the "/Modules" folder this way :

Code: Select all
sys.path.append(".../Modules")



2) Write my own script

In it absolute simplest version, if does nothing else than importing DaVinciResolveScript:
Code: Select all
try:
    import DaVinciResolveScript as dvr
except ImportError:
    print("could not import DaVinciResolveScript")
    exit(1)


=======

I tried running that script with several versions of Python. All of them fail, every time because of the "imp" package used by DaVinciResolveScript.

With Python 3.12 (i.e. the most recent Python):
PROBLEM : My script was working until the import of DaVinciResolveScript.py, which was crashing as early as its first line, because internally it imports module "imp" which is entirely deprecated in Python 3.12. You can't even use it anymore, it's a blocking deprecation.

Python 3.9 or 3.11 (slightly older versions) :
Module "imp" is still marked as deprecated, but at least it doesn't cause a crash to import it.
PROBLEM: When DaVinciResolveScript hits this instruction, it fails:
Code: Select all
            script_module = imp.load_dynamic("fusionscript", path + "fusionscript" + ext)

The issue is that it's not clear how or why it fails. It doesn't crash, it doesn't throw an error or raise an exception. But then the execution seems to ... vanish? The debugger has no steps to follow after it.
Maybe the execution enters a different thread/process to which the debugger is not attached? Is it just me who just lacks basic knowledge of how to debug Python modules?
Either way, it's no good.

I tried the recommended version : 3.6
PROBLEM: I can't even run the code in debug. VSCode's Python extension won't go further back than 3.7.
I tried to run the script from the command line, without being attached to a debugger. The import still seems to fail.



What am I doing wrong? Do you have a recommendation or a step-by-step guide?
Offline

JeanCall

  • Posts: 12
  • Joined: Tue Dec 19, 2023 3:38 pm
  • Real Name: Jean Callisti

Re: How to set up external Python in 2023?

PostThu Dec 28, 2023 7:51 am

Apparently I'm not the only one having this issue: https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=168568

A quick read tells me they solved the issue by using Python 3.10.
I will read further to see if there's any other useful tips.

Someone wrote :
My feeling is that Resolve chooses the latest Python version available on the machine and some sort of conflict arises when trying to connect to the API from an environment using an older version of Python.

Shameful!
Offline
User avatar

Igor Riđanović

  • Posts: 1656
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: How to set up external Python in 2023?

PostThu Dec 28, 2023 7:40 pm

Python 3.6 is the last version with imp.

For simplicity you have to install it in C:\Python36 or Resolve Studio won't find it. You actually can install it elsewhere, i.e. using pyenv, but you then have to symlink it from C:\Python36.

Make sure you're using Resolve Studio and that External scripting using Local is set in the preferences.
www.metafide.com - DaVinci Resolve™ Apps

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], Bruceqld, Christoph Schmid, Craig2000, panos_mts, pauliesheehy, ShutterlabCreative and 305 guests