fee-fi-fo-fum
article thumbnail
λ°˜μ‘ν˜•

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둜 확인할 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

 

 

λ°˜μ‘ν˜•
profile

fee-fi-fo-fum

@hae02y

ν¬μŠ€νŒ…μ΄ μ’‹μ•˜λ‹€λ©΄ "μ’‹μ•„μš”β€οΈ" λ˜λŠ” "κ΅¬λ…πŸ‘πŸ»" ν•΄μ£Όμ„Έμš”!