I’m using pyinstaller to create an executable file from python script to run on Windows.
My python script does depend on a package that compiled from C-module. Package’s name is MT5Manager, if you want to try.
I run script standalone without any error by python main.py
. But I retrieve error when I run by .exe file.
OS version: Windows 11
Python version: 3.12.3 from pyenv-win
pyinstaller==6.6.0
Please help me!
Here is step-by-step what I did:
- Create an virtualenv
python -m venv .venv
.venvScriptactivate
- Install package from pypi:
pip install MT5Manager pyinstaller
- create a
main.py
with content as follows:
import numpy # I use this because I don't want to use --hidden-import in pyinstaller command
import MT5Manager
print("Prepair")
manager = MT5Manager.ManagerAPI()
print("OK.")
Output when I run python main.py
standalone:
Prepair
OK.
Command I used to create executable file:
pyinstaller -F main.py --paths .venvLibsite-packages
Output when I run .distmain.exe
:
Prepair
Traceback (most recent call last):
File "main.py", line 5, in <module>
manager = MT5Manager.ManagerAPI()
^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'MT5Manager.ManagerAPI'> returned NULL without setting an exception
[6680] Failed to execute script 'main' due to unhandled exception!