Lecture 강의

Undergraduates 학부 Graduates 대학원 Lecture 역학 Lecture 설계 Lecture IT(IoT, AI) Lecture SAP2000 Lecture 아바쿠스 Lecture 파이썬 Lecture 엑셀 VBA Lecture 마이다스 Lecture 이탭스

[01. 설정] 1.4 (1) 실행 방법, (2) 실행 파일(exe) 만들기 - PyInstaller

작성자 : kim2kie

(2023-02-19)

조회수 : 960

[참조]

 

(1) 실행 방법
 1) 인터프리터에서 한줄씩 직접 타이팅하여 실행
 2) 텍스트에디터에서 스크립트(.py) 소스를 작성 후 인터프리터로 실행

(2) 실행 파일(exe) 만들기 - PyInstaller
 1) PyInstaller 설치
 2) 실행 파일 생성
 3) 실행 파일 실행

 


 

Python은 라인 단위로 구동되는 스크립트 언어이다. 
즉, Python을 구동하려면 인터프리터(python.exe)가 필요하다. 
실행하는 방식은 다음과 같은 두가지이다.

 

 (1) 실행 방식

1) 인터프리터에서 한줄씩 직접 타이팅하여 실행

  • cmd에서 Python 인터프리터(python.exe)를 구동한 후 한 줄씩 실행할 수 있다.
    Ex) >>> 
  • Spyder에서 IPython Console에서 한 줄씩 실행할 수 있다.
    Ex) In [1]:
  • Jupyter Notebook에서 한 줄씩 실행할 수 있다.
    Ex) In [ ]:


2) 텍스트에디터에서 스크립트(.py) 소스를 작성 후 인터프리터로 실행

  • cmd에서 다음과 같이 한 번에 실행할 수 있다.
    Ex) > python HelloPython.py
  • Spyder나 Jupyter에서 한 번에 실행할 수 있다.
    Ex) >>> import HelloPython

 

 

(2) 실행 파일(exe) 만들기

1) PyInstaller 설치
.Anaconda Prompt에서 pip로 pyinstaller 설치

.anaconda prompt창에서 설치
.이미 설치된 경우 already satisfied라는 메시지 뜸

 

Ex)
> conda install pyinstaller

 

.The current user does not have write permissions 메시지가 뜰 경우
 Anaconda Prompt를 검색한 후 우클릭하여 관리자 권한으로 실행

참조) 일반 cmd창에서 pyinstaller을 install 할 경우, conda 대신 pip를 사용

 

Ex)
> pip install pyinstaller

 

/그림 1. Administrator로 Anaconda Prompt에서 conda로 pyinstaller 설치/

 

2) 실행 파일 생성
.Python 파일(예: calendar.py)이 있는 폴더로 이동
.다음 명령어를 입력하면 해당 폴더 내에 [dist] 폴더에 실행파일 생성

 

Ex) 
> pyinstaller -F -w calendar.py

 

여기서 
--onefile 또는 -F : 하나의 파일로 실행 파일 생성
--noconsole 또는 --windowed 또는 -w : 실행 시 cmd창(console창)을 띄우지 않음

 

/그림 2. pyinstaller를 사용한 실행 파일 생성/

 

3) 실행 파일 실행
.[dist] 폴더로 이동하여, 생성된 exe 파일 실행
.gui인 경우 ui가 exe파일 내에 함께 존재하여야 함

 

/그림 3. calendar.ui와 함께 calendar.exe 실행/