안녕하세요.
여러가지 구글링 영끌을 통해 성공한 결과를 공유 드립니다.
- 모델: Yolov8-nano
- IR 모델: 모델 경량화 수행을 위해 .onnx 변환 후 openvino 형태의 .xml 파일 양자화(int8-quantization)까지 수행한 파일
기존에 만들어진 가상환경에서 pyinstaller 해서 .exe 만드려고 하니까 경로가 이상하게 잡혀있는 것 때문에 같은 오류가 반복적으로 발생했어요.
그래서 첫 과정부터 다시 수행해주었습니다.
1) 가상환경생성
conda create -n "name here" python=3.8
2) Pyinstaller 설치 & 필요 라이브러리 설치
pip install pyinstaller
pip install -r requirements.txt
(필요 라이브러리는 requirements.txt 파일에 넣어두어서 한 번에 설치하기)
3) pyinstaller로 .spec 파일 만들기
pyinstaller main.py
- 해당 과정이 조금 명료하지 못한 면이 있지만,
- pyinstaller main.py를 수행하면 build, dist 폴더 2개, .spec 파일 1개 총 3개가 생성돼요.
- 저는 .spec 파일이 필요하므로 생성된 build, dist 폴더는 다시 지워줍니다.
- .spec는 제가 필요한 것들을 더 담아서 build할 수 있는데요!
4) .spec 파일 안에 필요한 라이브러리 추가해주기 (중요과정*****)
여기서 이제 pathex, binaries, datas 3개에 필요 바이너리 파일, 파일, 등 다 추가해줄거에요!
a = Analysis(
['실행파일명.py'],
pathex=['아나콘다설치된곳\\Anaconda3\\envs\\가상환경이름\\Lib\\site-packages\\openvino\\libs'],
binaries=[('IR모델웨이트경로\\best-gun.bin', '.'), ('다른IR모델웨이트경로\\TinyVit_320dim.bin', '.')],
datas=[('IR모델경로\\best-gun.xml', '.'), ('아나콘다경로\\Anaconda3\\envs\\pyinstaller\\Lib\site-packages\\openvino\\inference_engine\\constants.cp38-win_amd64.pyd', '.'), ('다른IR경로\\TinyViT_320dim.xml', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
본인의 컴퓨터에 anaconda 가상환경 어디에 설치되어있는지 확인 꼭 필요해요.
본인 경로에 맞게 바꿔서 저와 같이 넣어주시면 돼요.
5) Ultralytics 폴더 추가해주기
분명 pip install -r requirements.txt 안에 ultralytics가 설치되어있는데 폴더 생성이 안되더라구요.
그래서 깃헙에서 ultralytics 다운받아서 수동으로 추가해주는 과정이 있었어요.
ultralytics>yolo>cfg>default.yaml 파일이 없다고 자꾸 에러가 났었거든요
6) openvino 관련 .dll 파일 가져와주기
C:\Users\user\Anaconda3\envs\pyinstaller\Lib\site-packages\openvino\libs
본인의 아나콘다환경에 접속하면 여기 폴더로 접근이 가능해요. 여기 엄청나게 많은 openvino 관련 .dll들이 있거든요
할 수 있는 파일 관련된거 다 추가해줬어요.
1) openvino.dll : 대장인 것 같아서 추가
2) openvino_auto_plugin.dll : device 작성할 때 auto로도 적어서 추가
3) openvino_intel_cpu_plugin.dll: device 작성할 때 cpu 적기도 하고 기기가 intel cpu니까 추가
4) openvino_ir_frontend.dll: 지금 사용하는 .xml파일이 ir 이니까 추가
5) openvino_pytorch_frontend.dll: 코드 내부에서 pytorch 연산 있으니 일단 추가
에러가 안나게 하기 위해서 관련될만한것들 모두 .dll 추가해줬어요.
해당 파일은 dist 폴더 내에 프로젝트 폴더 내에 .exe가 들어있는 폴더 내에 붙여넣기해서 위치시켜주시면 됩니다.
+ 추가로 이미지파일도 추가해줘야 화면이 뜨더라구요.
저는 icon 폴더에 이미지가 다 들어있어서
datas에
추가해줬어요!
그러면 dist>프로젝트폴더>.exe 경로 내에 icon 폴더 내에 이미지파일들이 모두 들어와있는것을 확인하실 수 있습니다.
성공..!!!!
진짜 일주일 넘게 시간 투자한 것 같아요 ㅠ 흑
이제 구글링에 도가 튼 것 같은...ㅎㅎ
Reference page:
1) pyinstaller 만들 때 파일 추가하는거
Unable to Execute build.exe from OpenVINO™ Python* Script Using...
How to add OpenVINO dependencies to the PyInstaller command line to generate a functional .exe file from an OpenVINO python script.
www.intel.com
2) .spec 파일 다루는거(한국어)
https://4uwingnet.tistory.com/4
파이썬 exe 만들기, pyinstaller python
python 으로 좀 큰 프로젝트를 하시는 분들은 쉽게쉽게 exe 파일이 생성이 안되는걸 종종 경험 하셨을 겁니다. 제가 사용하는 방법은 pyinstaller 를 사용해서 여러 패키지가 포함된 프로젝트를 exe 빌
4uwingnet.tistory.com
3) .dll 파일 추가해야하는거
https://github.com/openvinotoolkit/openvino/issues/11293
Pyinstaller issue with Openvino 2022.1 · Issue #11293 · openvinotoolkit/openvino
System information (version) OpenVINO=> 2022.1 Operating System / Platform => Winodws 64 Bit Virtual environment => Anaconda 4.9.2 Python => 3.8.12 Installation => From PyPI (pip install openvino) ...
github.com
4) 별로 도움은 안됐지만 pyinstaller시 멀티플 파일 추가하는법 (그냥 .spec로 하는게 좋음)
https://coderslegacy.com/add-image-data-files-in-pyinstaller-exe/
How to add image (data) files in Pyinstaller EXE - CodersLegacy
When creating an executable using Pyinstaller, it is often necessary to include additional data files such as an image, configuration file...
coderslegacy.com
5) 에러해결했던거
https://briana-ai.tistory.com/11
[Error] invalid add_data_or_binary value
[ENG] Problem: i want to import .xml file to read when i run my code .exe made by pyinstaller. But, i faced this error invalid add_data_or_binary value Command i write pyinstaller --add-data "path\model.xml" main.py Command i fix pyinstaller main.py --add-
briana-ai.tistory.com
'Python' 카테고리의 다른 글
MacOS에서 Jupyter 설치하고 실행하는 방법 (0) | 2023.08.18 |
---|---|
Python webcam usb 연결했는데 VideoCapture에서 시간 오래걸릴 때 해결법 (0) | 2023.08.02 |
Python 라이브러리 time, datetime (0) | 2023.08.02 |
Python에서 변수를 외부로 빼는 방법 - .ini 파일 활용하기 (0) | 2023.08.01 |
윈도우에서 프로그램 패포를 위해 PyInstaller 실행해서 .exe 파일 만들기 (0) | 2023.07.28 |