'PyAutoit : OSError: Cannot load AutoItX from path: C:\Users\User\AppData\Local\Temp\_MEI152482\autoit\lib\AutoItX3_x64.dll

I been trying to compile this program for quite some time but can't seem to figure out what is going on. From just reading the error code I'm assuming pyinstaller cannot or does not know where the needed AutoitX3_64.dll file. I've read other questions but cant seem to find a detailed answer explain how to tell my installer where the files are located.

I've tried: pyinstaller --onefile main.py (Fail) pyinstaller -w --onefile --add-data C:\Users\User\AppData\Local\Programs\Python\Python310\Lib\site-packages\autoit\lib\AutoItX3_x64.dll;autoit\lib main.py (Fail)

I've also dumped autoit folder in my build / dist with no success.

Any help would be greatly apriciated!

[error1][error2]



Solution 1:[1]

After searching this site and countless others i managed to figure out how to fix the error:

OSError: Cannot load AutoItX from path: 
C:\Users\myusername\AppData\Local\Temp\_MEI152482\autoit\lib\AutoItX3_x64.dll

The answer would be to make a spec file and tell it where the autoit files are located. Here is how!

When you run pyinstaller command it will automatically generate a filename.spec in your home dir. For example:

pyinstaller -w --onefile main.py

-w is no console --onefile is to compress all files into one executable. main.py is the file you are going to make into exe. Now you will see a filename.spec in your home dir. Edit that with the following datas and hiddenimports

datas=
[["C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\autoit\\lib\\AutoItX3_x64.dll", "autoit\\lib"]],

hiddenimports=["autoit.init", "autoit.autoit", "autoit.control", "autoit.process", "autoit.win" ],

Here is an example and don't forget to copy and paste the autoit\lib into your dist folder.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a6623