본문 바로가기
python 기본개념

pycharm 실행파일 만들기

by 자동매매 2022. 3. 15.

 

 

PyInstaller Manual — PyInstaller 4.10 documentation

© Copyright This document has been placed in the public domain.. Revision 669313ba.

pyinstaller.readthedocs.io

 

pyinstaller 모듈 설치

pip install pyinstaller

 

exe파일 설치 위치 : C:\Users\neo21\anaconda3\envs\win32_py37\Scripts\pyinstaller.exe

모듈 설치 위치 : C:\Users\neo21\anaconda3\envs\win32_py37\Lib\site-packages\PyInstaller

PyCharm에서 프로젝트에 종속적으로 설치된 모듈의 경우가 문제가 될 수 있음

 

[ cmd를 이용한 생성 ]

1. 해당 파일이 있는 디렉토리로 이동

2. CMD에서 pyinstaller 명령 실행

   pyinstaller 해당파일

   ex) pyinstaller main.py

   ## build 폴더, dist 폴더, main.spec파일도 함께 생성

   ## option

      --onefile / -F : 실행파일만 생성

      --noconsole / -w : console을 띄우지 않고 실행파일 실행

      --exclude : 제외모듈  ( --exclude pandas, --exclude numpy )

      --hidden-import : import 에러 발생 모듈 추가

      --add-data <SRC;DEST>  [예] --add-data README.txt;.

      --icon=아이콘 파일명

 

Using PyInstaller — PyInstaller 4.10 documentation

Making GNU/Linux Apps Forward-Compatible Under GNU/Linux, PyInstaller does not bundle libc (the C standard library, usually glibc, the Gnu version) with the app. Instead, the app expects to link dynamically to the libc from the local OS where it runs. The

pyinstaller.readthedocs.io

3. dist폴더내 실행파일 확인

 

[ PyCharm에서 Pyinstaller 연결 생성 ]

출처 : https://astrocosmos.tistory.com/158

 

1. setting

File>setting>Tools>External tools> + click

Arguments와 Working directory에서 "$"로 묶여있는 부분은 PyCharm에서 정의한 macro이다. 

 

Program : C:\Users\neo21\anaconda3\envs\win32_py37\Scripts\pyinstaller.exe

Arguments : --onefile --windowed $FilePath$ (콘솔 응용 프로그램일 경우 --windowed 옵션을 삭제하시면 됩니다)

Working directory : $ProjectFileDir$

 

2. Pyinstaller 실행방법

   실행파일 오른 마우스 버튼 클릭>External Tools click>editor tool name선택

3. 생성파일 확인

   해당 디렉토리>dist폴더에 생성

 

[ cx_Freeze를 이용한 exe파일 생성 ]

모듈설치

pip install cx-Freeze

 

1. setup.py파일 생성

exe파일을 생성할 파일과 동일 위치에 setup.py 생성

from cx_Freeze import setup, Executable
import sys

buildOptions = dict(packages=["PyQt5", "pandas", "sqlite3", "Kiwoom"],  # 포함시킬 모듈 지정
                    excludes=[])   # 제외할 모듈 지정

exe = [Executable("pytrader.py")]  # exe파일을 생성할 대상 파일

# setup 설정
setup(
    name='Trader',
    version='0.1',
    author="LTI",
    description="FIlter Adapter Application",
    options=dict(build_exe=buildOptions),
    executables=exe
)

2. cmd에서 명령실행 (setup.py가 위치한 디렉토리로 이동 후)

python setup.py build

 

 

 

 

'python 기본개념' 카테고리의 다른 글

보유종목현황  (0) 2022.03.17
주문창 구현  (0) 2022.03.17
pyinstaller로 만든 실행파일(exe) 에러처리  (0) 2022.03.15
키움 openAPI 자동 로그인  (0) 2022.03.12
문자열 서식  (0) 2022.03.09

댓글