Creating EXE from Python

A place for unofficial tutorials posted by MH users

Moderator: joepal

Creating EXE from Python

Postby chronolog » Thu May 29, 2014 1:39 pm

Hi All!
I`ve a problem. I`ve changed something in my makehuman .py code and now i don`t know how to compile all python scripts to one executable *.exe file.
Py2exe, PyInstaller, cx_Freeze were tested. They compiling for me one file without any dependencies. In Py2exe i can list all scripts as import, but it very difficult.
Can anyone help me? :(
chronolog
 
Posts: 2
Joined: Thu May 29, 2014 1:24 pm

Re: Creating EXE from Python

Postby joepal » Thu May 29, 2014 4:03 pm

We use pyinstaller for building the windows builds. The (somewhat messy) documentation for the procedure is here:

http://www.makehuman.org/doc/node/libra ... dures.html

Basically, run the scripts in the source root in order, then run pyinstaller with buildscripts/win32/makehuman.spec as argument.

However, this supposes you checked out the source from bitbucket. It won't work if you downloaded a build which was already made with pyinstaller.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4474
Joined: Wed Jun 04, 2008 11:20 am

Re: Creating EXE from Python

Postby joepal » Thu May 29, 2014 4:57 pm

chronolog wrote:Hi All!
I`ve a problem. I`ve changed something in my makehuman .py code and now i don`t know how to compile all python scripts to one executable *.exe file.


Also, if you already have the dependencies on the system, why bother with making an exe file in the first place? You can run the "makehuman.py" script right away in that case without bothering to compile anything.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4474
Joined: Wed Jun 04, 2008 11:20 am

Re: Creating EXE from Python

Postby chronolog » Fri May 30, 2014 8:27 am

joepal wrote:You can run the "makehuman.py" script right away in that case without bothering to compile anything.


Yep, I can! But sometimes need to run MH on other сomputers with WinOS, whose users don`t know that Python not only a snake.

Just one more fault. I`ve ran scripts sceannpz,cleanpyc, compile_models, compile_targets and after that ran pyinstaller with buildscripts/win32/makehuman.spec as argument.
And got error:

I: Dependent assemblies of C:\Python27\python.exe:
I: x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
Traceback (most recent call last):
File "C:\pyinstaller\Build.py", line 1494, in <module>
main(args[0], configfilename=opts.configfile)
File "C:\pyinstaller\Build.py", line 1472, in main
build(specfile)
File "C:\pyinstaller\Build.py", line 1429, in build
execfile(spec)
File "c:/makehuman/buildscripts/win32/makehuman.spec", line 34, in <module>
import build_prepare
ImportError: No module named build_prepare
:(
chronolog
 
Posts: 2
Joined: Thu May 29, 2014 1:24 pm

Re: Creating EXE from Python

Postby joepal » Fri May 30, 2014 10:19 pm

chronolog wrote:
joepal wrote:You can run the "makehuman.py" script right away in that case without bothering to compile anything.


Yep, I can! But sometimes need to run MH on other сomputers with WinOS, whose users don`t know that Python not only a snake.

Just one more fault. I`ve ran scripts sceannpz,cleanpyc, compile_models, compile_targets and after that ran pyinstaller with buildscripts/win32/makehuman.spec as argument.
And got error:

I: Dependent assemblies of C:\Python27\python.exe:
I: x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
Traceback (most recent call last):
File "C:\pyinstaller\Build.py", line 1494, in <module>
main(args[0], configfilename=opts.configfile)
File "C:\pyinstaller\Build.py", line 1472, in main
build(specfile)
File "C:\pyinstaller\Build.py", line 1429, in build
execfile(spec)
File "c:/makehuman/buildscripts/win32/makehuman.spec", line 34, in <module>
import build_prepare
ImportError: No module named build_prepare
:(


This is a simple path error. You need to cd to buildscripts/win32 and then run pyinstaller with makehuman.spec as argument. It assumes that all directories should be calculated from the current working dir. (and yeah, I know that's not altogether obvious from the docs).

Anyway, here's the sum total build routine we use on jenkins:

Code: Select all
set BRANCH=unstable

set ROOT=%CD%
set WORKSPACE=c:\jenkins\workspace
set DISTDIR=%WORKSPACE%\makehuman-%BRANCH%-dist
set PYINST=c:\jenkins\pyinstaller\pyinstaller.py
set JENKINS_DATE=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
set EXPECTED=%DISTDIR%\makehuman-%BRANCH%-%JENKINS_DATE%-win32.zip
set UNIX=c:\jenkins\unix
set SED=s/DATE/%JENKINS_DATE%/g
set KEY=c:\jenkins\tux.ppk
set SSH=CENSORED@ssh.tuxfamily.org
set NIGHTLY=makehuman/makehuman-repository/nightly
set DELFILE=%NIGHTLY%/makehuman-%BRANCH%*-win32.zip
set PUTTY="c:\program files (x86)\putty"
set PSCP=%PUTTY%\pscp
set PLINK=%PUTTY%\plink

echo %DISTDIR%
echo %EXPECTED%

%UNIX%\sed -e "%SED%" c:\jenkins\build.conf.unstable > %ROOT%\buildscripts\build.conf

rem copy c:\jenkins\makehuman.spec buildscripts\win32\makehuman.spec

cd %ROOT%\makehuman
call cleanpyc.bat
call cleannpz.bat

cd %ROOT%\buildscripts
cd win32

python %PYINST% -y makehuman.spec

dir %DISTDIR% > %ROOT%\dist.txt
dir %ROOT%\buildscripts\win32\dist\makehuman > %ROOT%\build.txt

cd %ROOT%

%UNIX%\sed -i -e "s/</\&lt;/g" dist.txt
%UNIX%\sed -i -e "s/>/\&gt;/g" dist.txt

%UNIX%\sed -i -e "s/</\&lt;/g" build.txt
%UNIX%\sed -i -e "s/>/\&gt;/g" build.txt

if not exist %EXPECTED% exit 1

%PLINK% -i %KEY% %SSH% rm -f %DELFILE%
%PSCP% -i %KEY% %EXPECTED% %SSH%:%NIGHTLY%


Maybe this is of some help.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4474
Joined: Wed Jun 04, 2008 11:20 am


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest