프로그래밍

Pyinstaller 사용시 selenium의 chromedriver 콘솔창 제거하는 방법

hydragon 2022. 1. 28. 23:32
반응형

 

selenium으로 만든 프로젝트를 pyinstaller로 프로그램을 만들 때 --noconsole 옵션을 주어도 검은색 콘솔창이 계속 나오는 경우가 있다. 이 경우에는 먼저

 

C:\Users\[사용자 이름]\anaconda3\envs\[가상환경 이름]\Lib\site-packages\selenium\webdriver\common

경로의 service.py를 찾아서 열어준다.

 

service.py 중간에 다음과 같은 항목이 보일것이다.

 

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

 

이 부분을

 

try:
    cmd = [self.path]
    cmd.extend(self.command_line_args())
    self.process = subprocess.Popen(cmd, stdin=PIPE, 
                                    stdout=PIPE,
                                    stderr=PIPE, 
                                    shell=False, 
                                    creationflags=0x08000000)
except TypeError:
    raise

 

이렇게 수정하면 된다. 그러면 더 이상 콘솔창이 보이지 않는다.

반응형