Is there a way to install selenium webdriver as a python project dependence.
I need this in such a way, so when this project goes to a os, that doesn't have selenium webdriver installed not to be an issue for this project to run properly on that os.
Thank you in advance.
PS: Please take a look at my own answer to this question.
Stefan
This is how I have done for all my projects.
Create a text file which has all the project dependencies mentioned. make sure you mentioned version as well. Example: requirement.txt
I solved my problem this way:
Installing selenium with the following command:
pip install --install-option="--prefix=<path_to_dependencies_in_my_python_project>" -U selenium
Import selenium module from this dependencies project folder
Also another approach is to check if the new OS has selenium installed and if not - install it via python script. The code looks something like that:
# windows
try:
from selenium import webdriver
except ModuleNotFoundError:
os.system("pip install --install-option=\"--prefix={}\" selenium"
.format(os.path.join(project_main_folder_path, "_depedencies")))
from selenium import webdriver
# Linux
try:
from selenium import webdriver
except:
os.system("pip install selenium -t {}"
.format(os.path.join(project_main_folder_path, "_depedencies", "Lib", "site-packages")))
from selenium import webdriver
Take a look at the difference of the pathing - on Linux it is installed directly in the folder, while on windows it is installed in sub-folder "Lib\site-packages". Also I don't know why, but I had problems with name 'ModuleNotFoundError' is not defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With