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๋ก ํ์ธํ ์๋ ์์ต๋๋ค.