Reputation: 11
I managed to create an .exe
file for Windows 10 with PyInstaller from this simple python script:
import cv2
print("Hello World!)
I also created a hook.py
file with this few lines of code:
sys.path.append(path)
old = os.environ.get('PATH', '')
paths=[path]
paths.append(old)
new = os.pathsep.join(paths)
os.environ['PATH'] = new
in order to update the path of the program.
The resulting exe is working: the dist
directory, in which the exe is located, contains the exe file, a set of dll
and pyd
files and the library directories (in this case: cv2
, numpy
).
Now, I need to move the dll files and the library directories from the current location to the directory that I have specified in the variable path
of the hook.py
. As I read in this answer, only few files are maintained in the exe directory (for example the pythonXX.dll
file).
The result is that the exe is not able to run emitting this error:
File "<path_to_minoconda>\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cv2\__init__.py", line 5, in <module>
ModuleNotFoundError: No module named 'cv2.cv2'
[1988] Failed to execute script temp
It seems the program is not able to correctly load the OpenCV library, even if I specified the path through the hook. The only way to run the program is putting the cv2 directory inside the same folder of the exe file. It is important to note that the dll files are correctly loaded (indeed, if I change the name of the folder with dll, the program is not able to locate them).
Thanks for any suggestion!
Upvotes: 1
Views: 507