I created a Selenium python program that I'd like to turn into an executable windows file. The Selenium program works with my terminal alone, but when I attempt to use pyinstaller I run into errors.
This is the error that I am getting:
(env) C:\Users\XXX\Documents\Selenium Python\dist>name
Traceback (most recent call last):
File "name.py", line 5, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "webdriver_manager\chrome.py", line 7, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "webdriver_manager\drivers\chrome.py", line 1, in <module>
ModuleNotFoundError: No module named 'packaging'
[15364] Failed to execute script 'name' due to unhandled exception!
My pip installs:
- pip install selenium
- pip install webdriver-manager
- pip install pyinstaller
Since I use Chrome for my browser and I have the 'chromedriver.exe' in the same folder as the project folder with the python file .
I create the executable with:
- pyinstaller --onefile name.py
- Add binaries=[('chromedriver.exe', '.')] to the generated name.spec
- pyinstaller name.spec
My name.py looks like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.get("https://www.google.com/")