Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyinstaller distributing opencv from Windows 10 to Windows <10, missing ucrt dlls api-ms-win-crt

I have a Python 3.5 64 bit program (required by tensorflow for Windows) that uses OpenCV. I am distributing it with pyinstaller.

I built my program with Windows 10

/c/Python35/Scripts/pyinstaller -c DeepMeerkat.spec

On my computer, the .exe builds and runs perfectly. On any other non-Windows 10 machine

On

import cv2

Returns

ImportError: DLL load failed: The specified module could not be found.

I can see a huge amount of discussion on this on pyInstaller thread, but I can't quite tell how to put it into practice. Dependency walker says I'm missing a number of DLLs

api-ms-win-crt-**.dll

Okay, from the pyInstaller threads, I know that these DLLs exist

C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs

Under multiple subfolders base on architecture.

I tried adding to my .spec file

pathex=["C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/"],

Or for my particular architecture

pathex=["C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/arm"],

Which is what I thought was being suggested here

"Install the Windows Software Development Kit (SDK) for Windows 10 and expand the .spec-file to include the required DLLs, see “Distributing Software that uses the Universal CRT“ in the above-mentioned link, number 6."

That did not have any effect. I am getting hundreds of errors like

121472 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\python35\DLLs\_ssl.pyd

But I can see that DLL here

C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\arm

enter image description here

So then I literally copied posthoc the entire folder

cp -r "C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/" dist/Lib/

But it's not clear how to connect these to the .exe. Clearly, letting pyInstaller know beforehand is preferable.

I also tried

/c/Python35/Scripts/pyinstaller --path "C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/arm" -c DeepMeerkat.spec

And it still did not find them

I've also tried adding that folder to PATH. Any ideas?

like image 804
bw4sz Avatar asked Sep 26 '17 00:09

bw4sz


People also ask

How to add a DLL to pyinstaller?

You need to add the .dll as `--add-binary' to make PyInstaller collect the dependencies of this .dll, too. Maybe some dynlib ist missing here, too. strace -f -e trace=file -o $TMP/trace.txt mxapp.app is your friend.

Is it possible to install OpenCV without Qt in Python?

If you do not need OpenCV imshow / GUI functionality, you can most probably avoid the issue by installing the headless version of opencv-python: opencv-python-headless which does not include Qt.

How do I download OpenCV for Windows?

Download opencv for windows from opencv.org Dlls will be in the bin folder Do not forget to add the dll folder to your windows system path variable and add correct libraries in your linker options. Tons of guides on google on how to do this.

What does API-MS-win-CRT-runtime-l1-1-0 DLL is missing mean?

Thanks for your feedback. "api-ms-win-crt-runtime-l1-1-0.dll is missing" is a common error on Windows running computers. This happens when the program does found the .dll file which is required in order to work or function.


1 Answers

If you would have provided your spec file I'd could see what's going on. From here its likely your not including files.

There is two methods to go from here:

  1. Create "one" single file that includes all dll's, pyd files and more... a large exe-file as result.
  2. The other way is to have it as file + folder filled with dll files, etc... you get a small exe-file.

Check add binary (incl. dll) files here the pyinstaller documentation about including files manually.

Check add data files here the pyinstaller documentation about including files manually.

An example spec-file that includes dll files from your dll folder.

block_cipher = None a = Analysis(['minimal.py'], pathex = ['/Developer/PItests/minimal'], binaries = [ ( 'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs', '.' ) ], datas = [ ('helpmod/help_data.txt', 'helpmod' ) ], hiddenimports = [], hookspath = None, runtime_hooks = None, excludes = None, cipher = block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher = block_cipher) exe = EXE(pyz,... ) coll = COLLECT(...)

like image 144
ZF007 Avatar answered Sep 20 '22 22:09

ZF007