python pyinstaller 에서 webdriver 사용시에 window console 창이 뜨지 않게 하는 방법 > 개발

본문 바로가기
사이트 내 전체검색

개발

python pyinstaller 에서 webdriver 사용시에 window console 창이 뜨지 않게 하는 방법

페이지 정보

profile_image
작성자 관리자 (112.♡.173.204)
댓글 0건 조회 3,955회 작성일 21-04-28 10:50

본문

## pyinstaller

python 파일을 윈도 실행파일로 만드는 방법 중에는 pyinstaller 를 이용하는 방법이 있다.
기본적인 사용방법과 옵션은 다음과 같다.

```
pyinstaller -w -F test.py
```
-w, --windowed, --noconsole : window cosole 창을 띄우지 않는다. 검은색 cmd 창
-F, --onefile : 하나의 실행파일로 만든다.

- 참고 : https://pyinstaller.readthedocs.io/en/stable/usage.html#options



## 문제점

pyinstaller 의 -w 옵션으로 만든 test.exe 파일 자체의 콘솔창은 뜨지 않는다.
그런데, webdriver 인 chromedriver.exe 의 콘솔창이 떠 버린다.

반대로, -w 옵션 없이 실행파일을 만들면, chromedriver.exe 의 콘솔창은 안뜨는데, test.exe 의 콘솔창이 떠 버린다.



## 해결방법

webdriver 의 service.py 파일의 내용을 약간 수정하여, 해결이 가능하다.

service.py 파일의 위치는 아래에 있으며, python 의 설치 위치에 따라 달라질 수 있다.

C:\Python39\Lib\site-packages\selenium\webdriver\common\service.py

service.py 파일에서 def start(self): 함수 부분의 Popen 에 creationflags=0x08000000 를 추가해 준다.

옵션을 주어 분기하는 방법도 있으나, 여기서는 그냥 일괄 처리한다. 분기 방법은 아래 참고를 참조하면 된다.



## service.py


```
        try:
            cmd = [self.path]
            cmd.extend(self.command_line_args())
            self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file,
                                            stderr=self.log_file,
                                            stdin=PIPE)
```


```
        try:
            cmd = [self.path]
            cmd.extend(self.command_line_args())
            self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file,
                                            stderr=self.log_file,
                                            stdin=PIPE,
                                            creationflags=0x08000000)
```
로 변경한다.


그리고, 실행파일을 다시 빌드하여 실행해 보면, 콘솔창이 뜨지 않는다.



## 참고
https://m.blog.naver.com/kibani/221921810439
https://sijoo.tistory.com/409
https://stackoverflow.com/questions/48654427/hide-command-prompt-in-selenium-chromedriver

추천0

댓글목록

등록된 댓글이 없습니다.

Total 386건 5 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
3062956004-29
3052186004-29
3042132004-29
3032826004-28
3022498004-28
열람중3956004-28
3001970004-25
2993028004-22
2981873004-14
2972329004-14
2962311004-12
2953259004-11
2942239004-07
2932981004-07
2923261003-25
2913354003-24
2903254003-06
2892308003-06
2882301003-01
2871699002-27

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.