I 've been reading almost all the posts related to this topic but I can´t find a solution!!!. My folder path is : C:\Users\User\Desktop\Data Analytics Arg\py_inst
Inside the folder I created a virtual env., I added the chromedriver.exe and my script as it can be seen in the image:
this is my script:
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)
I added to the service.py file (C:\Users\User\Desktop\Data Analytics Arg\py_inst\venv\Lib\site-packages\selenium\webdriver\common\service.py) : creationflags= CREATE_NO_WINDOW and imported CREATE_NO_ WINDOW from subprocess , like this:
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
and :
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)
All from this posts :
If I run the script, afther changes in service.py I got this message:
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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Could someone help me please???.
CodePudding user response:
This error message...
UPX is not available
...implies that pyinstaller can not find upx.exe
to encrypt exe file.
Solution
In order to fix this error you need to download upx as per your system configuration. Incase of a 64-bit windows OS you need to download:
Incase you have downloaded upx and saved in D:\
you need to do:
pyinstaller main.py --key 123456 -n test -F -w --upx-dir D:\