I created a python package and published it in PyPI. The package code is based on chromedriver selenium. I added the chromedriver file in the PyPI package folder and mentioned the file path in the code :
driver_path= Path.cwd() / "chromedriver"
However when I install the package using pip install my-package. The code returns the classical error:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
This can be solved only by manually downloading and adding the chromedriver to the package folder. Is there a better way to make the chromedriver automatically installed and configured when my PyPI package is installed?
I found a solution. The trick is to import your python package in your own code and then get the package path:
import Path
try:
import your_pypi_package
package_path=str(your_pypi_package.__path__).split("'")[1]
driver_path= Path(package_path) / "chromedriver"
except:
driver_path= Path.cwd() / "chromedriver"
driver = webdriver.Chrome(executable_path=driver_path, options=options)