gpt4 book ai didi

selenium - 163 信息 : UPX is not available. Selenium pyinstaller 一个文件.exe

转载 作者:行者123 更新时间:2023-12-03 08:13:00 28 4
gpt4 key购买 nike

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

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

enter image description here

这是我的脚本:

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.7124 信息:Python:3.10.0147 信息:平台:Windows-10-10.0.19042-SP0149 信息:写入 C:\Users\User\Desktop\Data Analytics Arg\py_inst\prueba_1.spec153 信息:UPX 不可用。找不到脚本“C:\Users\User\Desktop\Data Analytics Arg\py_inst\prueba_1.py”

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

enter image description here

如果我运行脚本,在 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。如果是 64 位 操作系统,您需要下载:

upx-for-windows-10.png

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

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

关于selenium - 163 信息 : UPX is not available. Selenium pyinstaller 一个文件.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70327138/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com