My PyPI installed package is unable to detect the chromedriver file

After creating a python package and publishing it in PyPI, I encountered an issue with the chromedriver selenium code. Despite adding the chromedriver file to the PyPI package folder and specifying the file path in the code as:

driver_path= Path.cwd() / "chromedriver"

When installing the package using pip install my-package, I faced the common error message:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

To resolve this, I had to manually download and include the chromedriver in the package folder. Is there a more efficient method for automatically installing and configuring the chromedriver when my PyPI package is installed?

Answer №1

Unfortunately, it is not feasible; your best course of action would be to provide detailed instructions to your user on installing Chrome and the chromedriver specific to their platform.

Answer №2

I have discovered the solution! The key is to include your python package in your own code and then retrieve the package path:

import Path
try:
            import my_pypi_package
            package_path=str(my_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)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the drag-and-drop feature in Ruby on Rails version 3

Is there a way to replicate drag and drop actions in rspec request specs? In my scenario, I need to move the #divItem element to the #divContainer element using jQuery. After refreshing the page, I want to verify that the #divItem is now inside the #divCo ...

A comparison between XPath and JQuery locators when using Selenium

After discovering that individuals utilize JQuery element-locators in Selenium, I am intrigued by the concept. I would like to inquire about the advantages of using JQuery selectors over XPath selectors. Are they considered more adaptable or quick, parti ...

Choosing a date from a jQuery datepicker-Ui with Selenium WebDriver

Is there a way for Selenium web driver to choose a specific date from a jQuery datepicker-UI and input it into a date field? 1) I attempted using Jscript to set the date, but it seems that the date must be chosen from the jQuery pop-up window for the form ...

I'm curious if it is possible to retrieve the dates of actions on websites using Selenium with Python

Is there a way to retrieve the date of data, like the date of comments, using HTML codes? I need assistance on how to achieve this through selenium in Python. Can Jquery be used as a solution? ...

Exception encountered for Internet Explorer when attempting to launch from WebDriver: 405 Method Not Allowed

After trying to launch IE from Webdriver and clicking on save, I encountered a "405 Method not allowed" exception. However, when I manually launched IE and clicked on save, it worked fine. I'm perplexed by this issue. Any ideas as to why it might be ...