163 信息:UPX 不可用。硒 pyinstaller 一个 file.exe

163 INFO: UPX is not available. selenium pyinstaller one file.exe

我已经阅读了几乎所有与此主题相关的帖子,但我找不到解决方案!!!。 我的文件夹路径是:C:\Users\User\Desktop\Data Analytics Arg\py_inst

在我创建虚拟环境的文件夹中,我添加了 chromedriver.exe 和我的脚本,如图所示:

这是我的脚本:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import  expected_conditions as EC
from selenium.webdriver.common.by  import By
import time

def resource_path(relative_path):

try:
    import sys
    import os
    # PyInstaller creates a temp folder and stores path in _MEIPASS
    base_path = sys._MEIPASS
except Exception:
    base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)

try :

url = "https://pinterest.com"
driver_path = "chromedriver.exe"

#Instanciamos la clase de Options para definir ciertas opciones:
options = Options()
options.add_argument("--lang=es") #lenguaje que queremos utilizar
#options.add_argument("--headless") # utilizar un navegador sin cabeza
options.add_argument("--log-level=3")# omite los warnings en la consola

#definimos ntro.webdriver:

driver = webdriver.Chrome(executable_path=driver_path, options=options)
driver.get(url)

time.sleep(2)

buttons = driver.find_elements_by_css_selector("button[data-test-id='page-scroll-arrow']")
for button in buttons:
    opacity = button.get_attribute("style").split(";")[0][-1]
    if opacity is '1':
        button.click()
    
time.sleep(3)

texto = driver.find_element_by_css_selector('h2.unauth-homepage-signup-title').text
with open('result.txt','w') as file:
    file.write(texto)

driver.close()

except Exception as e: 
    print(e)

我添加到service.py文件(C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\Lib\site-packages\selenium\webdriver\common\service.py) : creationflags= CREATE_NO_WINDOW 并从 subprocess 导入 CREATE_NO_ WINDOW ,像这样:

from subprocess import CREATE_NO_WINDOW, DEVNULL

import errno
import os
import subprocess
from platform import system
from subprocess import PIPE, CREATE_NO_WINDOW
from time import sleep
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common import utils

和:

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,
                                        creationflags=CREATE_NO_WINDOW)

全部来自这个帖子:

hide_chrome_answer

最后,我尝试通过终端创建一个 .exe 文件:

pyinstaller --add-data "chromedriver.exe;." --windowed --onefile prueba_1.py

但是我得到了这个错误:

124 信息:PyInstaller:4.7 124 信息:Python:3.10.0 147 信息:平台:Windows-10-10.0.19042-SP0 149 信息:写 C:\Users\User\Desktop\Data 分析 Arg\py_inst\prueba_1.spec 153 信息:UPX 不可用。 找不到脚本 'C:\Users\User\Desktop\Data Analytics Arg\py_inst\prueba_1.py'

现在我的文件夹是这样的:

如果我 运行 脚本,在 service.py 中进行更改后,我收到此消息:

c:\Users\User\Desktop\Data Analytics Arg\py_inst\prueba_script.py:41: SyntaxWarning: 
"is" with a literal. Did you mean "=="?
  if opacity is '1':
Traceback (most recent call last):
  File "c:\Users\User\Desktop\Data Analytics Arg\py_inst\prueba_script.py", line 1, in 
<module>
 from selenium import webdriver
  File "C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\lib\site- 
  packages\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\lib\site- 
  packages\selenium\webdriver\firefox\webdriver.py", line 31, in <module>
    from .service import DEFAULT_EXECUTABLE_PATH, Service
  File "C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\lib\site- 
  packages\selenium\webdriver\firefox\service.py", line 20, in <module>
    from selenium.webdriver.common import (service, utils)
  File "C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\lib\site- 
  packages\selenium\webdriver\common\service.py", line 77
    creationflags=CREATE_NO_WINDOW)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

有人可以帮帮我吗???

这个错误信息...

UPX is not available

...表示pyinstaller找不到upx.exe来加密exe文件。


解决方案

为了修复此错误,您需要下载 upx as per your system configuration. Incase of a 64-bit OS 您需要下载:

如果您已下载 upx 并保存在 D:\ 中,您需要执行以下操作:

pyinstaller main.py --key 123456 -n test -F -w --upx-dir D:\