Python μ€ν νμΌ(exe) λ§λ€κΈ°
λ§€λ² .pyλ‘ μ€ννκΈ° λ²κ±°λ‘μμ .exe μ€ννμΌλ‘ λ§λ€μμ΅λλ€. exe νμΌμ λ§λλ λ°©λ²μ μ¬λ¬κ°μ§ λ§μ§λ§, μ¬λ¬ λ°©λ² μ€ νλμΈ pyinstaller λͺ¨λμ μ΄μ©ν exe νμΌ λ§λλ λ°©λ²μ ν¬μ€ν νμ΅λλ€.
μ€ννκ²½
μ΄μ체μ : window 10
νμ΄μ¬ λ²μ : python 3.7
pyinstaller μ€μΉ
pipλ₯Ό μ΄μ©νλ©΄ κ°λ¨νκ² μ€μΉ ν μ μμ΅λλ€.
컀맨λ λͺ λ Ήμ΄
>> pip install pyinstaller
C:\Users\75385\Desktop>pip install pyinstaller
Collecting pyinstaller
Downloading https://files.pythonhosted.org/packages/03/32/0e0de593f129bf1d1e77eed562496d154ef4460fd5cecfd78612ef39a0cc/PyInstaller-3.4.tar.gz (3.5MB)
100% |ββββββββββββββββββββββββββββββββ| 3.5MB 3.3MB/s
Installing build dependencies ... done
Requirement already satisfied: setuptools in c:\users\75385\appdata\local\programs\python\python37-32\lib\site-packages (from pyinstaller) (40.6.2)
Collecting pefile>=2017.8.1 (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/ed/cc/157f20038a80b6a9988abc06c11a4959be8305a0d33b6d21a134127092d4/pefile-2018.8.8.tar.gz (62kB)
100% |ββββββββββββββββββββββββββββββββ| 71kB 5.2MB/s
Collecting macholib>=1.8 (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/41/f1/6d23e1c79d68e41eb592338d90a33af813f98f2b04458aaf0b86908da2d8/macholib-1.11-py2.py3-none-any.whl
Collecting altgraph (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/0a/cc/646187eac4b797069e2e6b736f14cdef85dbe405c9bfc7803ef36e4f62ef/altgraph-0.16.1-py2.py3-none-any.whl
Collecting pywin32-ctypes (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/9e/4b/3ab2720f1fa4b4bc924ef1932b842edf10007e4547ea8157b0b9fc78599a/pywin32_ctypes-0.2.0-py2.py3-none-any.whl
Collecting future (from pefile>=2017.8.1->pyinstaller)
Downloading https://files.pythonhosted.org/packages/90/52/e20466b85000a181e1e144fd8305caf2cf475e2f9674e797b222f8105f5f/future-0.17.1.tar.gz (829kB)
100% |ββββββββββββββββββββββββββββββββ| 829kB 5.0MB/s
Installing collected packages: future, pefile, altgraph, macholib, pywin32-ctypes, pyinstaller
Running setup.py install for future ... done
Running setup.py install for pefile ... done
Running setup.py install for pyinstaller ... done
Successfully installed altgraph-0.16.1 future-0.17.1 macholib-1.11 pefile-2018.8.8 pyinstaller-3.4 pywin32-ctypes-0.2.0
μ€μΉκ° μλ£λμμ΅λλ€.
exe νμΌ λ§λ€κΈ°
ν μ€νΈμ© test.py λ§λ€κΈ°
import datetime
if __name__ == "__main__" :
print("Start.")
cur_time = datetime.datetime.now()
print("Current time : %s" % cur_time)
print("End.")
νμ¬ μκ°μ μΆλ ₯ν΄μ£Όλ κ°λ¨ν νλ‘κ·Έλ¨μ λλ€.
test.pyκ° μλ λλ ν λ¦¬λ‘ μ΄λνμ¬, pyinstaller λͺ λ Ήμ΄λ₯Ό μ λ ₯ν΄μ€λλ€.
>> pyinstaller --onefile test.py
μ°Έκ³ λ‘ --onefile μ΄λΌλ μ΅μ μ λ£μ΄μ£Όλ©΄, νλμ μ€ννμΌλ‘ μμ±μ΄ λ©λλ€. (μ°Έκ³ λ‘, --noconsole μ΅μ μ λ£μ΄μ£Όλ©΄ μ½μμ°½μ΄ λ¨μ§ μκ³ μ€νμ΄ λ©λλ€.)
μ€ν κ²°κ³Ό
λͺ λ Ήμ΄λ₯Ό μ€ννλ©΄, μ΄μκ°μ΄ dist, build λ± μ¬λ¬κ°μ νμΌμ΄ μμ±λ©λλ€.
dist ν΄λλ‘ λ€μ΄κ°λ³΄λ©΄, μλμ κ°μ΄ μ€ννμΌ(test.exe)μ΄ μμ±λκ²μ νμΈ ν μ μμ΅λλ€.
λλΈ ν΄λ¦νμ¬ μ€νν μ λ μκ³ , cmdλ‘ νμΈν μλ μμ΅λλ€.