It’s really a huge work for me this week to compile my nlk program with new interface into exe. I ran into a lot of problems. Fortunately, I managed to solve them through Googling. I will note some of the major problems below.
1.No module named *** :
At firse I was trying py2exe. However, a lot of modules can not be included in py2exe. So I turned to pyinstaller. I can get a exe file with pyinstaller, but when i ran it, a command window flashed out and report “No mudule named ***”. I included the missing files in the bat file one by one according to the reports. That leads my bat file to be very lengthy:
pyinstaller -F -w myscript.py --hidden-import=scipy.special._ufuncs_cxx --hidden-import=scipy.integrate --hidden-import=scipy.integrate.quadrature --hidden-import=scipy.integrate.odepack --hidden-import=scipy.integrate._odepack --hidden-import=scipy.integrate.quadpack --hidden-import=scipy.integrate._quadpack --hidden-import=scipy.integrate.quadpack --hidden-import=scipy.integrate._ode --hidden-import=scipy.integrate.vode --hidden-import=scipy.integrate._dop --hidden-import=scipy.integrate.lsoda
Most of the files are from scipy.integrate. I guess there should be a simpler method to include the whole folder with one command which i don’t know at the moment.
after all these test-and-modify, I finally got an “executable” executable file.
2. get rid of the black window on running .exe: this is very simple. Just as the bat file shown above, a simple “-w” solved this problem.
3. file already exists but should not: ***pyconfig.h:
Before my program opened its window, there was another window which reports: file already exists but should not: *****(a path which i can not remember now)/pyconfig.h.
I found the solution here:
when I start the compiling Bat file, a .spec file which contains the compiling configuration information was generated in the same folder with the file name “myscript(.spec)”. What i have to do is to modify this spec file. just like the answer in the above link, I have to add after a=Analysis something like this :
for d in a.datas:
if 'pyconfig' in d:
Then, I have to modify the bat file. Because All the required compiling configurations are in the spec file now, I should not re-run the previous bat file to over write spec, but call the spec file directly in bat. The new bat file is very short:
pyinstaller nlk.spec pause
4.myscript.exe not a valid win32 application:
My exe worked fine on win64. But when I ran it on a 32bit XP, it reported “myscript.exe not a valid win32 application”.
My script was written and compiled in a 64-bit version Winpython. It seems that I have to install a new 32-bit winpython.
So I installed 32-bit winpython and installed qtutil and pyinstaller which was not contained in winpython.I compiled the script in 32wp, and ran it again. Still, it reported the same error. Then I found that although I had unregistered the 64wp and registered the 32wp, the path in environment variable still point to the 64wp.So I modified the environment variable to 32wp and tried again. This time the compiling comand window reported a new error:
Solution to this error is:
First, up date pip to latest version:
python -m pip install --upgrade --force pip
Second, re-install pyinstaller with the new pip (I’m not sure if this step is necessary).
Third, compile with the new pyinstaller.
After all these strivings, I finally got an executable file that worked perfectly on both 64bit and 32bit windows systems. Special thanks to GOOGLE without which I might never complete my work.