pyinstaller one file --no-console does not work “Fatal Error”

前端 未结 3 1469
醉酒成梦
醉酒成梦 2020-12-06 08:44

I try 2 options with pyinstaller one with console and one without.

I am using Windows 10, Python 3.5.4, Windows Chrome Driver 2.33 and Selnium 3.6.0 and Pyinstaller

相关标签:
3条回答
  • 2020-12-06 08:53

    I hope this helps someone:

    C:\Users\%user_name%\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\selenium\webdriver\common

    Add import and change in "def start":

    from win32process import CREATE_NO_WINDOW

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

    if error, check pywin32: pip install pywin32

    0 讨论(0)
  • 2020-12-06 09:03

    after some search I found the full solution : Firstly go to -

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

    Change :

    self.process = subprocess.Popen(cmd, env=self.env,
                                                close_fds=platform.system() != 'Windows',
                                                stdout=self.log_file, stderr=self.log_file)
    

    To:

    self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)
    

    now simply build your app.py like this:

    pyinstaller --noconsole --onefile  --noupx   Yourfile.py
    
    0 讨论(0)
  • 2020-12-06 09:16

    Firstly go to- C:\Python35\Lib\site-packages\selenium\webdriver\common\service.py

    then in def start(self):

    def start(self): """ Starts the Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        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)``
    

    Just add creationflags=0x08000000 , I've already added there in the code. creationflags is a constant. It will work fine.

    or, you might also replace it with creationflags=CREATE_NO_WINDOW and add this line code from win32process import CREATE_NO_WINDOW.

    In my case, first method was working.

    0 讨论(0)
提交回复
热议问题