Basically my code runs fine in Pycharm, but when I convert it to exe using Pyinstaller, it doesn't work and gives me error.
I've tried some changes but all attempts failed.
Selenium.py
from selenium import webdriver
import ctypes
from webdriver_manager.firefox import GeckoDriverManager
#driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
user32 = ctypes.windll.user32
width = user32.GetSystemMetrics(0) # 2560 mine for example
height = user32.GetSystemMetrics(1) # 1440 mine for example
wT = width / 3
hT = height / 2
wB = width / 2
answer = height / 36
hB = (height / 2) - answer
wPa = width / 3
wPa2 = wPa * 2
hPa = height / 2
wPa3 = width / 2
def Window1():
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get("https://www.google.co.uk/")
driver.set_window_size(wT, hT)
driver.set_window_position(0, 0)
driver.switch_to.window(driver.window_handles[0])
if __name__ == '__main__':
Window1()
Run.py
import threading
import Selenium
import time
t1 = threading.Thread(target=Selenium.Window1)
t1.start()
time.sleep(2)
^that is a cut down version of my code, mine opens 5 windows instead of 1 but this is just for an example of what I'm doing/how I'm threading it. Hopefully this is enough.
This is the error i get when i try to run the exe:
It seems that PyInstaller can't resolve webdriver_manager
. So you just need to add whole library as a data file with add-data
:
pyinstaller -F --add-data ".\env\Lib\site-packages\webdriver_manager;webdriver_manager" script.py
Remember to replace the webdriver_manager
path with a correct one.