How can I fix this geckodriver error in Python? - python-3.x

I started learning selenium, and when I ran this code...
from selenium import webdriver
browser = webdriver.Firefox()
print(type(browser))
When I ran that code, I got this error - Message: 'geckodriver' executable needs to be in PATH.
How can I fix this error? I'm working on Firefox 64bit, and my Selenium Version is '3.141.0'.

gekodriver is detected in the 3 following ways.
1. Using environment variable PATH
Add the absolute path to the gekodriver directory into the environmental variable PATH.
export PATH=PATH:/ABSOLUTE/PATH/TO/PARENT_DIRECTORY_OF/gekodriver
2. Current directory
Keep the gekodriver executable in the current directory where the Python script is being executed from.
3. Passed as executable_path
For example,
webdriver.Firefox(executable_path="c:\\gekodriver.exe")

The error is fixed, I just put the geckodriver.exe into the Python39 folder and it works now perfectly!

Related

How to convert a selenium webscraping script to exe file?

I've created a script using selenium and chromedriver on pycharm that works absolutely fine. I want to create an exe of that script so that I can run it on other PCs without installing python or the other dependencies. I've tried using pyinstaller but it is not working. Can someone guide me how can I convert that script into exe.
Thanks!!!
You are getting any error ? as pyinstaller is the best option to turn your script in to executables.

Trying to test Python on Win 10, getting Errno 2. Path to python is given to the value of env variable

I've installed Python 3.8 on Win 10 machine. Path to Python is C:\Users\userid\AppData\Local\Programs\Python\Python38\
Path environment variable values are: C:\Users\userid\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe
In order to test python, I created a simple script called "script.py" in directory C:\python_scripts.
Then I tried to run "script.py" from the directory where it is located, but got error:
C:\python_scripts> python script.py
C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'script.py': [Errno 2] No such file or directory
What might be the cause of getting this error? i tried to run the script with both cmd and powershell, with the usual user rights and with elevated admin rights, still getting Errno 2.
No other versions of Python have been previously installed on this machine (which is a corporate one, if that might be significant)
Thank you
Thank you #OferSadan for your suggestion to use dir command, it helped me to solve the problem. The "script.py" had an additional .txt extension added to it for some reason, but the Windows explorer only showed .py extension by default. Now I deleted the trailing .txt suffix and the script runs

WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. - selenium

Before you let me know that this is a duplicate, the issue I am facing is that I am running my python code using a jupyter-notebook via an Ubuntu subsystem on Windows.
I have made sure that the path to the folder on Windows where chromedriver is located is correct. However, I am still getting the same error. Further, I am unable to see where my files from the Ubuntu subsystem are (ie, I can't find a folder on Windows with those files).
Anyway in which I can correct this? such as editing the ~/.bashrc file on Ubuntu?
browser = webdriver.Chrome("C:/Users/vr235/Downloads/chromedriver/chromedriver.exe")
Error:
WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
EDIT:
While a solution was pointed by user DebanjanB and marked as duplicate, I tried the user's suggestion but got the same error.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Users\vr235\Downloads\chromedriver\chromedriver.exe')
browser.get("https://www.sciencedirect.com/")
Error:
WebDriverException: Message: 'C:\Users\vr235\Downloads\chromedriver\chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
In case one is using a WSL, one can identify the path where the Chromedriver is present by viewing the mnt folder on WSL.
For instance: My chromedriver path was in the Downloads folder in C:/ drive
Path : /mnt/c/vr235/Users/Downloads/chromedriver.exe
Once you add the same, the above lines of code work perfectly.

Pycharm tensorflow ImportError but works fine with Terminal

I made a virtualenv with tensorflow installed and I changed Python interpreter set to the location where the virtualenv is located at. When I ran the program, it gives the error:
ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
I have the following lines written in my .bashrc file
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
export PATH=${CUDA_HOME}/bin:${PATH}
Also, I found the libcudnn.so.5 file in the following path:
/usr/local/cuda-8.0/lib64
I encountered this error before I opened PyCharm and I did manage to install the correct cudnn version. The problem is, I can use
$ source [virtualenv_path]
to active the virtualenv and run python in terminal and everything works fine, no errors shown. The program also runs without error in Pycharm's terminal but it just gives me the above error whenever I click the run button. Could there still be something wrong with the environment variable? How do I fix it?
Unfortunately in pycharm you have to set CUDA_HOME and LD_LIBRARY_PATH inside the IDE. To do that go to the Run menu->edit configurations then choose your project. Then you click on the Environment Variables and add an entry for CUDA_HOME and LD_LIBRARY_PATH. When you have done that you can run directly from inside pycharm. I would also recommend setting the defaults to have these paths as well, so you don't have to do this for every project. Also it wouldn't hurt to make sure you have the interpreter from source [virtualenv_path] set while you are on this setting page. Let me know if you have trouble finding where to do this.
I've read this other Stackoverflow post: Pycharm environment different than command line, and it seems that the problem is that openning PyCharm in the normal way won't preserve the bash environment. The solution is to open PyCharm from the command line and everything works now. All you need to do is to open PyCharm using charm and everything works fine now.
I have searched a lot, but I didn't find the right solution for this question anywhere. I found the solution with my friends and I would like to share with you also.
If your Tensorflow works in terminal properly but doesn't work in Pycharm you have two solutions:
1- Open Pycharm from Terminal. For me:
pycharm-community
2- If you are using Unity, you need to edit .profile, because Pycharm doesn't preserve .bashrc: So, open a terminal and type:
gedit .profile
Then, add the following codes at the end of the opened file:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Save and exit. Now, you can work with Tensorflow in Pycharm without the necessity of opening the Pycharm form terminal.

cx_Freeze: Python error in main script (function not found)

I am trying to create an exe from python script using cx_freeze
I have been able to create the build and test it successfully on win7 but whenever I try to run the exe on win xp I get the following error.
Have tried uninstalling and reinstalling cx_freeze but it wont help.
I am using python 3.4
AttributeError: function 'SetProcessDPIAware' not found
Complete error description
Got the solution.
Build the application on win xp pc.
Add the following lines to your setup file-
os.environ["TCL_LIBRARY"]=r"C:\Python34\tcl\tcl8.6"
os.environ["TCLLIBPATH"]=r"C:\Python34\tcl\tcl8.6"
os.environ["TK_LIBRARY"]=r"C:\Python34\tcl\tk8.6"
All must point to the correct tcl paths within the python setup.
In my case it was looking for tcl in some other location due to some environment variable confusion.
And build your script using cx_freeze again.
Will work like a charm.

Resources