Nuitka: Nuitka doesn't work with pywebview

I’m trying to use the Python module pywebview with Nuitka and I’m not able to to get it to work. I’ve tried to manually copy over the WebBrowserInterop.x86.dll and WebBrowserInterop.x64.dll files from site-packages/webview/lib and still no success. Am I missing something or is Nuitka not linking/including something correctly?

Python, Nuitka, and System Information

0.6.3.1
Python: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] 
Executable: C:\Python37\python.exe
OS: Windows
Arch: x86_64

main.py

import webview

webview.create_window(title="Hello World!", url="https://www.google.com/")

build.sh

#!/bin/bash

if [ "$1" == "" ]; then
  echo "Usage: $0 -source"
  exit 1
fi

if [ -d "./dist" ]; then
  rm -rf ./dist
  mkdir ./dist
else
  mkdir ./dist
fi

python -m nuitka --show-progress --standalone --recurse-all --experimental=use_pefile --experimental=use_pefile_recurse --experimental=use_pefile_fullrecurse --include-package=webview --output-dir=./dist $1

d="$(sed s/[\.py]//g <<< $1)"

mv ./dist/$d.dist/* ./dist

rm -rf ./dist/$d.build
rm -rf ./dist/$d.dist

./main.exe

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Users\jason\Projects\scratchpad\webview\dist\Python.Runtime.dll' or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at clrModule.PyInit_clr()

Any help on this would be great! – Jason.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Thanks, those pointers will be good enough.

I think for Nuitka, this ought to be good enough:

    # Unfrozen path
    dll_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib', dll_name)
    if os.path.exists(dll_path):
        return dll_path

That should point to webview/util as a folder for the DLLs inside the dist folder, because __file__ is updated correctly with Nuitka. Not sure why PyInstaller needs more help there, but I also don’t care.