ããã¯ããªã«ãããããŠæžãããã®ïŒ
Pythonã¢ããªã±ãŒã·ã§ã³ããå®è¡å¯èœãã€ããªãçæããããšãã§ãããã®ãšããŠã¯ãPyInstallerãæåã§ãã
PyInstaller Manual — PyInstaller 6.3.0 documentation
GitHub - pyinstaller/pyinstaller: Freeze (package) Python programs into stand-alone executables
ãã®ããã°ã§ãæ±ã£ãããšããããŸãã
PyInstallerを使って、Pythonアプリケーションから単一の実行可能ファイルを作成する - CLOVER🍀
ãªã®ã§ãããå¥ã®ããŒã«ãšããŠNuitkaãšãããã®ãããããšãç¥ã£ãã®ã§ãä»åã¯ãã¡ããè©ŠããŠã¿ãããšæããŸãã
Nuitka
Nuitkaã®Webãµã€ãã¯ãã¡ãã
Nuitka the Python Compiler — Nuitka the Python Compiler documentation
GitHubãªããžããªãŒã¯ãã¡ãã§ãã
Nuitkaã¯Pythonã§æžãããæé©åPythonã³ã³ãã€ã©ãŒã§ãã€ã³ã¹ããŒã©ãŒãå¿
èŠãšããªãå®è¡å¯èœãã€ããªãäœæã§ãããã®ã ãš
ãããŠããŸãã
Nuitka is the optimizing Python compiler written in Python that creates executables that run without an need for a separate installer.
Nuitka the Python Compiler / What is Nuitka
圢æ
ãšããŠã¯ã¹ã¿ã³ããŒãçãšåçšçããããã¹ã¿ã³ããŒãçã§ã³ãŒããäŸåé¢ä¿ããã³ããŒã¿ãã²ãšã€ã®å®è¡å¯èœãã¡ã€ã«ã«
ãã³ãã«ã§ããŸããé«éåãæ¡åŒµã¢ãžã¥ãŒã«ã®å©çšãã§ãããšãããŠããŸãã
- Nuitka the Python Compiler / What is Nuitka / Nuitka Standard
- Nuitka the Python Compiler / What is Nuitka / Nuitka Commercial
åçšçã§ã¯å®è¡å¯èœãã¡ã€ã«ãã³ãŒããããŒã¿ãªã©ãä¿è·ããããšãã§ããããã«ãªããšãããŠããŸãã
ãŠãŒã¶ãŒããã¥ã¢ã«ã¯ãã¡ãã
Nuitka User Manual — Nuitka the Python Compiler documentation
Nuitkaã«å¿ èŠãªãã®ã¯ã以äžã®ããã§ãã
- Cã³ã³ãã€ã©ãŒ ⊠C11ãŸãã¯C++03ããµããŒãããCã³ã³ãã€ã©ãŒ
- Python ⊠Python 2.6ã2.7ãŸãã¯Python 3.4ã3.5ã3.6ã3.7ã3.8ã3.9ã3.10ã3.11
- OS ⊠LinuxãFreeBSDãNetBSDãmacOS XãWindows
- CPUã¢ãŒããã¯ãã£ãŒ ⊠x86ãx86_64 (amd64)ãarm
Nuitka User Manual / Requirements
ã¡ãªã¿ã«ããŠãŒã¹ã±ãŒã¹ãèŠãŠã¿ããšå®è¡å¯èœãã¡ã€ã«ãçæããã ãã§ã¯ãªããŠãæ¡åŒµã¢ãžã¥ãŒã«ãçæããããã§ããããã§ãã
Nuitka User Manual / Use Cases
ä»åã¯åçŽãªPythonã¹ã¯ãªãããšãPyInstallerã®æã«ãè¡ã£ãå€éšã©ã€ãã©ãªãŒã«requestsãšBeatiful Soupã䜿ã£ãäŸãè©ŠããŠã¿ãããš
æããŸãã
PyInstallerを使って、Pythonアプリケーションから単一の実行可能ファイルを作成する - CLOVER🍀
ç°å¢
ä»åã®ç°å¢ã¯ãã¡ãã
$ python3 --version Python 3.10.12 $ pip3 --version pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
ä»®æ³ç°å¢ã䜿ããŸãããäœæã¯çç¥ããŸãã
OSã¯Ubuntu Linux 22.04 LTSã§ãã
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy $ uname -srvmpio Linux 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
åäœç¢ºèªã¯âŠPythonãå ¥ã£ãŠããªãç°å¢ãšããããšã§ãUbuntu Linuxã®ã³ã³ããå ã§è¡ãããšã«ããŸãã
$ docker container run -it --rm -v $(pwd):/host ubuntu:22.04 bash # python bash: python: command not found # python3 bash: python3: command not found
Nuitkaãã€ã³ã¹ããŒã«ãã
Nuitkaã®ã€ã³ã¹ããŒã«æ¹æ³ã§ãããpipãLinux OSã®å Žåã¯å€éšãªããžããªãŒãè¿œå ããããšã§OSããã±ãŒãžãšããŠãã€ã³ã¹ããŒã«
ããããšãã§ããŸãã
Nuitka Downloads — Nuitka the Python Compiler documentation
macOSãŸãã¯Windowsã®å Žåã¯ãpipã§ã®ã€ã³ã¹ããŒã«ã«ãªããŸãã
ä»åã¯pipã§ã€ã³ã¹ããŒã«ããããšã«ããŸãã
$ pip3 install nuitka
ã€ã³ã¹ããŒã«ãããããŒãžã§ã³ã
$ pip3 list Package Version ----------- ------- Nuitka 2.0.3 ordered-set 4.1.0 pip 22.0.2 setuptools 59.6.0 zstandard 0.22.0
ã€ã³ã¹ããŒã«ãããšãnuitka3
ããã³nuitka3-run
ãšããã³ãã³ãã䜿ããããã«ãªããŸããã
$ nuitka3 --version 2.0.3 Commercial: None Python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] Flavor: Debian Python Executable: /path/to/venv/bin/python3 OS: Linux Arch: x86_64 Distribution: Ubuntu (based on Debian) 22.04.4 Version C compiler: /usr/bin/gcc (gcc 11). $ nuitka3-run --version 2.0.3 Commercial: None Python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] Flavor: Debian Python Executable: /path/to/venv/bin/python3 OS: Linux Arch: x86_64 Distribution: Ubuntu (based on Debian) 22.04.4 Version C compiler: /usr/bin/gcc (gcc 11).
nuitka3-run
ã¯ãPythonã¹ã¯ãªãããã³ã³ãã€ã«ããŠçŽæ¥å®è¡ããããšããã³ãã³ãã ããã§ãã
ãã«ãã確èªã§ããŸãã
$ nuitka3 --help Usage: nuitka3 [--module] [--run] [options] main_module.py Options: --help show this help message and exit --version Show version information and important details for bug reports, then exit. Defaults to off. ãçç¥ã
âŠèšå€§ãªãªãã·ã§ã³ã䞊ã³ãŸããã
ã·ã³ãã«ãªPythonã¹ã¯ãªããã§è©Šã
ãã¡ã€ã«ãèªã¿èŸŒãã§ããã¡ã€ã«åãšè¡çªå·ãåºåããã¹ã¯ãªãããæžããŠã¿ãŸãã
app.py
import sys path = sys.argv[1] print(f"print: {path}") print() with open(path, "r") as f: count = 0 for line in f: count += 1 print(f"{count}: {line}", end="")
ã¹ã¯ãªããèªèº«ãæå®ããŠãåäœç¢ºèªã
$ python3 app.py app.py print: app.py 1: import sys 2: 3: path = sys.argv[1] 4: 5: print(f"print: {path}") 6: print() 7: 8: with open(path, "r") as f: 9: count = 0 10: 11: for line in f: 12: count += 1 13: print(f"{count}: {line}", end="")
ãã£ãããªã®ã§ããŸãã¯nuitka3-run
ã§è©ŠããŠã¿ãŸãããã
$ nuitka3-run app.py app.py Nuitka-Options: Used command line options: app.py Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure that is intended. Nuitka: Starting Python compilation with Nuitka '2.0.3' on Python '3.10' commercial grade 'not installed'. Nuitka: Completed Python level compilation and optimization. Nuitka: Generating source code for C backend compiler. Nuitka: Running data composer tool for optimal constant value handling. Nuitka: Running C compilation via Scons. Nuitka-Scons: Backend C compiler: gcc (gcc 11). Nuitka-Scons: Backend linking program with 6 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka: Keeping build directory 'app.build'. Nuitka: Successfully created 'app.bin'. Nuitka: Launching 'app.bin'. print: app.py 1: import sys 2: 3: path = sys.argv[1] 4: 5: print(f"print: {path}") 6: print() 7: 8: with open(path, "r") as f: 9: count = 0 10: 11: for line in f: 12: count += 1 13: print(f"{count}: {line}", end="")
åäœãèŠãŠãããšãCã³ã³ãã€ã©ãŒãåããŠããå®è¡ããŠããããã§ãã
ãªã®ã§ãå®è¡æéã¯ããªã䌞ã³ãŸãã
$ time nuitka3-run app.py app.py ãçç¥ã real 0m5.903s user 0m9.197s sys 0m0.532s
ã¡ãªã¿ã«ãå®è¡ãããš[ã¹ã¯ãªããå].bin
ãšããå®è¡å¯èœãã¡ã€ã«ãšapp.build
ãšãããã£ã¬ã¯ããªãã§ããŠããŸããã
$ ll åèš 5872 drwxrwxr-x 4 xxxxx xxxxx 4096 2æ 21 15:41 ./ drwxrwxr-x 4 xxxxx xxxxx 4096 2æ 21 14:51 ../ -rwxrwxr-x 1 xxxxx xxxxx 5988376 2æ 21 15:41 app.bin* drwxrwxr-x 3 xxxxx xxxxx 4096 2æ 21 15:41 app.build/ -rw-rw-r-- 1 xxxxx xxxxx 191 2æ 21 15:30 app.py drwxrwxr-x 5 xxxxx xxxxx 4096 2æ 21 15:19 venv/
ãã®app.bin
ã ãã§å®è¡ã§ããŸããâŠã
$ ./app.bin app.py print: app.py 1: import sys 2: 3: path = sys.argv[1] 4: 5: print(f"print: {path}") 6: print() 7: 8: with open(path, "r") as f: 9: count = 0 10: 11: for line in f: 12: count += 1 13: print(f"{count}: {line}", end="")
äœæããããã¡ã€ã«ãšãã£ã¬ã¯ããªã¯ã1床åé€ã
$ rm -rf app.bin app.build/
ã§ã¯ãå®è¡å¯èœãã€ããªãäœæããŠã¿ãŸãã--standalone
ãªãã·ã§ã³ãä»ããã¿ããã§ãã
$ nuitka3 --standalone app.py
ãããšãpatchelfãšããããã±ãŒãžããªããšæãããŸããâŠã
Nuitka-Options: Used command line options: --standalone app.py FATAL: Error, standalone mode on Linux requires 'patchelf' to be installed. Use 'apt/dnf/yum install patchelf' first.
ã€ã³ã¹ããŒã«ããŸãã
$ sudo apt install patchelf
ä»åºŠã¯åããŸãããnuitka3-run
ãšã¯æ¯ã«ãªããªããããå®è¡æéã䌞ã³ãŸãã
$ nuitka3 --standalone app.py
å®è¡ãã°ã
Nuitka-Options: Used command line options: --standalone app.py Nuitka: Starting Python compilation with Nuitka '2.0.3' on Python '3.10' commercial grade 'not installed'. Nuitka-Plugins:anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka: Completed Python level compilation and optimization. Nuitka: Generating source code for C backend compiler. Nuitka: Running data composer tool for optimal constant value handling. Nuitka: Running C compilation via Scons. Nuitka-Scons: Backend C compiler: gcc (gcc 11). Nuitka-Scons: Backend linking program with 7 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka: Keeping build directory 'app.build'. Nuitka: Successfully created 'app.dist/app.bin'.
2åç®ã®å®è¡æéã¯ãããããã§ããããååã¯ãã£ãšé ãã£ãããã«æããŸãã
real 0m21.296s user 0m21.324s sys 0m0.592s
app.build
ãšapp.dist
ãšãã2ã€ã®ãã£ã¬ã¯ããªãã§ããŠããŸãã
$ ll -h åèš 24K drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 15:45 ./ drwxrwxr-x 4 xxxxx xxxxx 4.0K 2æ 21 14:51 ../ drwxrwxr-x 3 xxxxx xxxxx 4.0K 2æ 21 15:47 app.build/ drwxrwxr-x 2 xxxxx xxxxx 4.0K 2æ 21 15:47 app.dist/ -rw-rw-r-- 1 xxxxx xxxxx 191 2æ 21 15:30 app.py drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 15:19 venv/
ã³ãã³ãã®å®è¡çµæãèŠããšãapp.dist
ãã£ã¬ã¯ããªã«ããapp.bin
ãšãããã¡ã€ã«ã䜿ãããã§ãã
$ ll -h app.dist åèš 11M drwxrwxr-x 2 xxxxx xxxxx 4.0K 2æ 21 15:47 ./ drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 15:45 ../ -rw-rw-r-- 1 xxxxx xxxxx 154K 2æ 21 15:47 _codecs_cn.so -rw-rw-r-- 1 xxxxx xxxxx 162K 2æ 21 15:47 _codecs_hk.so -rw-rw-r-- 1 xxxxx xxxxx 34K 2æ 21 15:47 _codecs_iso2022.so -rw-rw-r-- 1 xxxxx xxxxx 270K 2æ 21 15:47 _codecs_jp.so -rw-rw-r-- 1 xxxxx xxxxx 142K 2æ 21 15:47 _codecs_kr.so -rw-rw-r-- 1 xxxxx xxxxx 114K 2æ 21 15:47 _codecs_tw.so -rw-rw-r-- 1 xxxxx xxxxx 57K 2æ 21 15:47 _multibytecodec.so -rwxrwxr-x 1 xxxxx xxxxx 9.1M 2æ 21 15:47 app.bin* -rw-rw-r-- 1 xxxxx xxxxx 196K 2æ 21 15:47 libexpat.so.1
ã§ã¯ããã®ãã¡ã€ã«ãPythonãªãã§å®è¡ã§ããã確èªããŠã¿ãŸãããã
$ docker container run -it --rm -v $(pwd):/host ubuntu:22.04 bash
ãã¡ã€ã«ãã³ããŒããŠ
# cd # cp /host/app.dist/app.bin ./. # cp /host/app.py ./.
å®è¡ã
# ./app.bin app.py ./app.bin: error while loading shared libraries: libexpat.so.1: cannot open shared object file: No such file or directory
æãããŸããâŠãapp.dist
ãã£ã¬ã¯ããªå
ã«ãã£ãlibexpat.so.1
ãšãããã¡ã€ã«ããªããšèšã£ãŠããŸãã
ãšããããšã¯ãapp.dist
ãã£ã¬ã¯ããªãäžžããšã³ããŒããã°ããããã§ããã
# cp -R /host/app.dist ./.
å®è¡ã
# ./app.dist/app.bin app.py print: app.py 1: import sys 2: 3: path = sys.argv[1] 4: 5: print(f"print: {path}") 6: print() 7: 8: with open(path, "r") as f: 9: count = 0 10: 11: for line in f: 12: count += 1 13: print(f"{count}: {line}", end="")
ä»åºŠã¯ããŸããããŸããã
ããã¡ãã£ãšããæ¹ãééã£ãŠããæ°ãããŸããã©ããããã®ç®çã§ã¯--onefile
ãšãããªãã·ã§ã³ã䜿ãã®ãæ£è§£ã®ããã§ãã
1床çæããããã¡ã€ã«ãåé€ã
$ rm -rf app.build app.dist
--onefile
ãªãã·ã§ã³ãæå®ããŠãå床ãã«ãã
$ nuitka3 --onefile app.py
å®è¡ãã°ã
Nuitka-Options: Used command line options: --onefile app.py Nuitka: Starting Python compilation with Nuitka '2.0.3' on Python '3.10' commercial grade 'not installed'. Nuitka: Completed Python level compilation and optimization. Nuitka: Generating source code for C backend compiler. Nuitka: Running data composer tool for optimal constant value handling. Nuitka: Running C compilation via Scons. Nuitka-Scons: Backend C compiler: gcc (gcc 11). Nuitka-Scons: Backend linking program with 7 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Postprocessing: Creating single file from dist folder, this may take a while. Nuitka-Onefile: Running bootstrap binary compilation via Scons. Nuitka-Scons: Onefile C compiler: gcc (gcc 11). Nuitka-Scons: Onefile linking program with 1 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Onefile: Using compression for onefile payload. Nuitka-Onefile: Onefile payload compression ratio (30.98%) size 10628308 to 3292890. Nuitka-Onefile: Keeping onefile build directory 'app.onefile-build'. Nuitka: Keeping dist folder 'app.dist' for inspection, no need to use it. Nuitka: Keeping build directory 'app.build'. Nuitka: Successfully created 'app.bin'.
ä»åºŠã¯ãå
ã»ã©ã®app.build
ãapp.dist
ã«å ããŠapp.bin
ãšãããã¡ã€ã«ãšapp.onefile-build
ãšãããã£ã¬ã¯ããªãå¢ããŸããã
$ ll -h åèš 3.4M drwxrwxr-x 6 xxxxx xxxxx 4.0K 2æ 21 15:57 ./ drwxrwxr-x 4 xxxxx xxxxx 4.0K 2æ 21 14:51 ../ -rwxrwxr-x 1 xxxxx xxxxx 3.3M 2æ 21 15:57 app.bin* drwxrwxr-x 3 xxxxx xxxxx 4.0K 2æ 21 15:56 app.build/ drwxrwxr-x 2 xxxxx xxxxx 4.0K 2æ 21 15:57 app.dist/ drwxrwxr-x 3 xxxxx xxxxx 4.0K 2æ 21 15:57 app.onefile-build/ -rw-rw-r-- 1 xxxxx xxxxx 191 2æ 21 15:30 app.py drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 15:19 venv/
app.onefile-build
ã®äžèº«ã¯ãããªæãã§ãã
$ tree app.onefile-build app.onefile-build âââ @link_input.txt âââ onefile_definitions.h âââ scons-report.txt âââ static_src âââ OnefileBootstrap.c -> /path/to/venv/lib/python3.10/site-packages/nuitka/build/static_src/OnefileBootstrap.c âââ OnefileBootstrap.o 1 directory, 5 files
ããã§ãapp.bin
ãã¡ã€ã«ã䜿ãã°ããã®ã§ããããïŒ
å床確èªããŠã¿ãŸãã
$ docker container run -it --rm -v $(pwd):/host ubuntu:22.04 bash # cd # cp /host/app.bin ./. # cp /host/app.py ./.
å®è¡ã
# ./app.bin app.py print: app.py 1: import sys 2: 3: path = sys.argv[1] 4: 5: print(f"print: {path}") 6: print() 7: 8: with open(path, "r") as f: 9: count = 0 10: 11: for line in f: 12: count += 1 13: print(f"{count}: {line}", end="")
ã§ããŸãããããã§è¯ãããã§ãã
--standalone
ã--onefile
ã®ã©ã¡ãã®ãªãã·ã§ã³ã䜿ã£ãŠãPythonã©ã³ã¿ã€ã ãªãã«ã§ããããã§ãããåäžã®ãã¡ã€ã«ã«ãŸãšããã«ã¯
--onefile
ãªãã·ã§ã³ã䜿ãããšã«ãªãããã§ãã
--standalone
ãªãã·ã§ã³ã®å Žåã¯dist
ãã£ã¬ã¯ããªããšã³ããŒã®ãæ£è§£ã®ããã§ãã
ã§ã¯--standalone
ã--onefile
ã®éãã¯ïŒãšããããšãªã®ã§ããã--onefile
ãªãã·ã§ã³ã®å Žåã¯ããŒã¿ãã¡ã€ã«ãå«ãŸããªããªãããã§ãã
For data files to be included, use the option --include-data-files=
Use Case 4 - Program Distribution
ãªã®ã§ããã«ãããŠåããã©ããã¯ãŸã--standalone
ãªãã·ã§ã³ã§ç¢ºèªããåé¡ãªãããã§å¿
èŠãªã--onefile
ãªãã·ã§ã³ãè©Šããæ¹ã
ãããšãããŠããŸãã
äŸåã©ã€ãã©ãªãŒã䜿ã£ãŠè©Šã
次ã¯ãä»ã«ã©ã€ãã©ãªãŒãã€ã³ã¹ããŒã«ããŠè©ŠããŸãããã
å ãã¿ã¯ãã¡ãã®ãšã³ããªãŒã§ããããããã°ãPythonã¹ã¯ãªãããåå²ããŠã©ããªãããè©ŠããŠããã®ã§ããã¡ããèžè¥²ããŸãããã
PyInstallerを使って、Pythonアプリケーションから単一の実行可能ファイルを作成する - CLOVER🍀
Nuitkaãã€ã³ã¹ããŒã«ããåŸããã¡ããè¿œå ã
$ pip3 install requests beautifulsoup4
ã€ã³ã¹ããŒã«ãããããŒãžã§ã³ã
$ pip3 list Package Version ------------------ -------- beautifulsoup4 4.12.3 certifi 2024.2.2 charset-normalizer 3.3.2 idna 3.6 Nuitka 2.0.3 ordered-set 4.1.0 pip 22.0.2 requests 2.31.0 setuptools 59.6.0 soupsieve 2.5 urllib3 2.2.1 zstandard 0.22.0
æå®ãããURLã«ã¢ã¯ã»ã¹ããŠãtitle
ãååŸããã¹ã¯ãªããã
func.py
from bs4 import BeautifulSoup import requests def get_title(url): response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') return soup.title.text
èµ·åã¹ã¯ãªãããã¢ã¯ã»ã¹ãã察象ã¯ããã®ããã°ã«ããŸãã
app.py
from func import get_title title = get_title('https://kazuhira-r.hatenablog.com/') print(f"https://kazuhira-r.hatenablog.com/'s title = {title}")
ãŸãã¯å®è¡ç¢ºèªã
$ python3 app.py https://kazuhira-r.hatenablog.com/'s title = CLOVERð
OKã§ããã
ã§ã¯ãä»åºŠã¯Nuitkaã䜿ã£ãŠãããªã--onefile
ã§åäžã®å®è¡å¯èœãã¡ã€ã«ã«ããŠã¿ãŸãã
$ nuitka3 --onefile app.py
å®è¡ãã°ã
Nuitka-Options: Used command line options: --onefile app.py Nuitka: Starting Python compilation with Nuitka '2.0.3' on Python '3.10' commercial grade 'not installed'. Nuitka-Plugins:anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka: Completed Python level compilation and optimization. Nuitka: Generating source code for C backend compiler. Nuitka: Running data composer tool for optimal constant value handling. Nuitka: Running C compilation via Scons. Nuitka-Scons: Backend C compiler: gcc (gcc 11). Nuitka-Scons: Backend linking program with 87 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Plugins:data-files: Included data file 'certifi/cacert.pem' due to package data for 'certifi'. Nuitka-Postprocessing: Creating single file from dist folder, this may take a while. Nuitka-Onefile: Running bootstrap binary compilation via Scons. Nuitka-Scons: Onefile C compiler: gcc (gcc 11). Nuitka-Scons: Onefile linking program with 1 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Onefile: Using compression for onefile payload. Nuitka-Onefile: Onefile payload compression ratio (23.73%) size 48561227 to 11524727. Nuitka-Onefile: Keeping onefile build directory 'app.onefile-build'. Nuitka: Keeping dist folder 'app.dist' for inspection, no need to use it. Nuitka: Keeping build directory 'app.build'. Nuitka: Successfully created 'app.bin'.
2åç®ã®èšæž¬çµæã§ããããã«ãã«ããã£ãæéã
real 2m9.833s user 6m7.061s sys 0m7.561s
çµæã
$ ll -h åèš 12M drwxrwxr-x 7 xxxxx xxxxx 4.0K 2æ 21 16:19 ./ drwxrwxr-x 4 xxxxx xxxxx 4.0K 2æ 21 14:51 ../ drwxrwxr-x 2 xxxxx xxxxx 4.0K 2æ 21 16:16 __pycache__/ -rwxrwxr-x 1 xxxxx xxxxx 12M 2æ 21 16:19 app.bin* drwxrwxr-x 3 xxxxx xxxxx 20K 2æ 21 16:18 app.build/ drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 16:19 app.dist/ drwxrwxr-x 3 xxxxx xxxxx 4.0K 2æ 21 16:19 app.onefile-build/ -rw-rw-r-- 1 xxxxx xxxxx 148 2æ 21 16:13 app.py -rw-rw-r-- 1 xxxxx xxxxx 183 2æ 21 16:12 func.py drwxrwxr-x 5 xxxxx xxxxx 4.0K 2æ 21 16:11 venv/
確èªããŠã¿ãŸãã
$ docker container run -it --rm -v $(pwd):/host ubuntu:22.04 bash # cd # cp /host/app.bin ./.
å®è¡ã
# ./app.bin
ãšã©ãŒã«ãªããŸããâŠããããã¯çµµæåãåºåããããã®codecã足ããªãããã§ããâŠãããã°ã¿ã€ãã«ã«çµµæåãå ¥ããŠãããâŠã
Traceback (most recent call last): File "/tmp/onefile_11_1708500050_281074/app.py", line 5, in <module> UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f340' in position 51: ordinal not in range(128)
ãšãããããã¬ãŒã¹ããã¯ãèŠããšPythonã®ã¹ã¯ãªããåãåºãŠããããšã«ã¡ãã£ãšé©ããŸãããå
éšçã«ã¯å
ã®ã¹ã¯ãªããã
å«ãŸããŠããŠãåçšçã ãšæå·åã§ãããšããã®ã¯ãã®ãããã®è©±ãªã®ã§ããããã
ä»æ¹ããªãã®ã§æ¥æ¬èªã®èšèªããã¯ãã€ã³ã¹ããŒã«ããŠãèšèªèšå®ã
# apt update && apt install language-pack-ja # export LANG=ja_JP.UTF-8 # export LANGUAGE=ja_JP:
ä»åºŠã¯åããŸããïŒ
# ./app.bin https://kazuhira-r.hatenablog.com/'s title = CLOVERð
ãªã®ã§ãäŸåã©ã€ãã©ãªãŒããã³è€æ°ãã¡ã€ã«ã®å©çšãOKã§ããã
ããã§ããããããšã¯ã²ãšãšããã§ããæãã§ãã
ãããã«
Nuitkaã䜿ã£ãŠãPythonã¢ããªã±ãŒã·ã§ã³ããåäžã®å®è¡å¯èœãã¡ã€ã«ãäœæããããšãè©ŠããŠã¿ãŸããã
åäœç¢ºèªã«ã³ã³ããã䜿ã£ãã®ã§å€ãªãããæ¹ããããããŸãããã䜿ãæ¹èªäœã¯ããã»ã©æžæããªãã£ãã§ãããœãŒã¹ã³ãŒã以å€ã®
ãã¡ã€ã«ãå«ãããšãã©ãããæåã«ãªãã®ãã¯ç¢ºèªããŠããŸãããã
ä»åã¯ãããããã§ããããªããšã