I solved my problem this way:
- Installing pip for the current OS I am working on
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.