@@ -11,10 +11,11 @@ This is the documentation for Pyarmor 3.4 and later.
1111 - [ Use Project to Manage Obfuscated Scripts] ( #use-project-to-manage-obfuscated-scripts )
1212 - [ Standalone Package] ( #standalone-package )
1313 - [ Package Used by Outer Scripts] ( #package-used-by-outer-scripts )
14- - [ Pack Obfuscated Scripts with py2exe and cx_Freeze] ( #pack-obfuscated-scripts-with-py2exe-and-cx_freeze )
1514 - [ Many Obfuscated Package Within Same Python Interpreter] ( #many-obfuscated-package-within-same-python-interpreter )
1615 - [ Change Default Project Configuration] ( #change-default-project-configuration )
1716 - [ Distribute Obfuscated Scripts] ( #distribute-obfuscated-scripts )
17+ - [ Pack Obfuscated Scripts with py2exe and cx_Freeze] ( #pack-obfuscated-scripts-with-py2exe-and-cx_freeze )
18+ - [ Pack Obfuscated Scripts with PyInstaller] ( #pack-obfuscated-scripts-with-pyinstaller )
1819 - [ License of Obfuscated Scripts] ( #license-of-obfuscated-scripts )
1920 - [ Cross Platform] ( #cross-platform )
2021 - [ Use runtime path] ( #use-runtime-path )
@@ -254,38 +255,6 @@ it used by clear script `examples/testpkg/main.py`
254255 python main.py
255256```
256257
257- #### Pack Obfuscated Scripts with py2exe and cx_Freeze
258-
259- From v4.4, introduces a command ` pack ` to pack obfuscated scripts with py2exe,
260- cx_Freeze etc.
261-
262- First install py2xe
263-
264- pip install py2exe
265-
266- Then write ` setup.py ` for py2exe, here is an example script
267- ` examples/py2exe/setup.py ` . There are 2 scripts in this example, entry script
268- ` hello.py ` and ` queens.py ` . To be sure it works
269-
270- cd examples/py2exe
271- python setup.py py2exe
272-
273- After that, run command ` pack ` to pack obfuscated scripts
274-
275- python pyarmor.py pack --type py2exe examples/py2exe/hello.py
276-
277- Check the output path of ` examples/py2exe/dist ` , the runtime files required by
278- obfuscated scripts are copied here, and the ` library.zip ` is updated, the
279- original ` queens.pyc ` replaced with obfuscated one.
280-
281- For cx_Freeze, py2app, it's almost same as py2exe. Learn more options
282- about command [ pack] ( #pack )
283-
284- Quick start from the following template scripts
285-
286- * [ pack-obfuscated-scripts.bat] ( examples/pack-obfuscated-scripts.bat ) for Windows
287- * [ pack-obfuscated-scripts.sh] ( examples/pack-obfuscated-scripts.sh ) for most of others
288-
289258#### Many Obfuscated Package Within Same Python Interpreter
290259
291260Suppose there are 3 odoo modules ` web-login1 ` , ` web-login2 ` ,
@@ -444,6 +413,79 @@ For package which used by other scripts:
444413machine. To be exact, the magic string value used to recognize
445414byte-compiled code files (.pyc files) must be same.
446415
416+ #### Pack Obfuscated Scripts with py2exe and cx_Freeze
417+
418+ From v4.4, introduces a command ` pack ` to pack obfuscated scripts with py2exe,
419+ cx_Freeze etc.
420+
421+ First install py2xe
422+
423+ pip install py2exe
424+
425+ Then write ` setup.py ` for py2exe, here is an example script
426+ ` examples/py2exe/setup.py ` . There are 2 scripts in this example, entry script
427+ ` hello.py ` and ` queens.py ` . To be sure it works
428+
429+ cd examples/py2exe
430+ python setup.py py2exe
431+
432+ After that, run command ` pack ` to pack obfuscated scripts
433+
434+ python pyarmor.py pack --type py2exe examples/py2exe/hello.py
435+
436+ Check the output path of ` examples/py2exe/dist ` , the runtime files required by
437+ obfuscated scripts are copied here, and the ` library.zip ` is updated, the
438+ original ` queens.pyc ` replaced with obfuscated one.
439+
440+ For cx_Freeze, py2app, it's almost same as py2exe. Learn more options
441+ about command [ pack] ( #pack )
442+
443+ Quick start from the following template scripts
444+
445+ * [ pack-obfuscated-scripts.bat] ( examples/pack-obfuscated-scripts.bat ) for Windows
446+ * [ pack-obfuscated-scripts.sh] ( examples/pack-obfuscated-scripts.sh ) for most of others
447+
448+ #### Pack Obfuscated Scripts with PyInstaller
449+
450+ Here is one of workaround to pack obfuscated scripts with ` PyInstaller ` , this
451+ example will distribute a script ` hello.py ` and moudle file ` queens.py `
452+
453+ First obfuscate all the ` .py ` file in the path ` testmod ` to ` dist/obf `
454+
455+ pyarmor obfuscate --src testmod --entry hello.py --no-restrict --output dist/obf
456+
457+ Then run pyinstaller to build the bundle to ` dist/hello/ ` , this command will
458+ generate ` hello.spec ` either
459+
460+ cd /path/to/pyarmor/examples
461+ pyinstaller testmod/hello.py
462+
463+ Edit ` hello.spec ` , change ` Analysis ` , add obfuscated script and date files as
464+ the following way
465+
466+ a = Analysis(['testmod/hello.py', 'dist/obf/hello.py'],
467+ datas=[('dist/obf/*.lic', '.'), ('dist/obf/*.key', '.'), ('dist/obf/_pytransform.*', '.')],
468+
469+ After ` Analysis ` , insert code to replace original python scrips and moudles with
470+ obfuscated ones
471+
472+ a.scripts[0] = 'hello', 'dist/obf/hello.py', 'PYSOURCE'
473+ for i in range(len(a.pure)):
474+ if a.pure[i][1].startswith(a.pathex[0]):
475+ a.pure[i] = a.pure[i][0], a.pure[i][1].replace('/testmod/', '/dist/obf/'), a.pure[i][2]
476+
477+ Next run pyinstaller with this ` hello.spec `
478+
479+ pyinstaller hello.spec
480+
481+ Finally run exetuable with obfuscated scripts
482+
483+ dist/hello/hello
484+
485+ # Check the scripts are obfuscated
486+ rm dist/hello/license.lic
487+ dist/hello/hello
488+
447489### License of Obfuscated Scripts
448490
449491There is a file ` license.lic ` in the output path "dist", the default
0 commit comments