i cannot access python selenium chromedriver form jupiter Notebook - list

pip install selenium
After installing selenium in jupiter
i have download chromedriver and saved it to C:\Program Files\Google\Chrome\Application\chromedriver.exe
from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chromedriver.exe")
driver.get("https://instagram.com")
**I am getting error like please help to use chromedriver using jupiter notebook any help will be appreciated
Even i have add Root path, r string, nothing worked**
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
/srv/conda/envs/notebook/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
/srv/conda/envs/notebook/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
728 errread, errwrite,
--> 729 restore_signals, start_new_session)
730 except:
/srv/conda/envs/notebook/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1363 err_msg += ': ' + repr(err_filename)
-> 1364 raise child_exception_type(errno_num, err_msg, err_filename)
1365 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe': 'C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe'
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
<ipython-input-8-924a85514f82> in <module>
1 from selenium import webdriver
----> 2 driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chromedriver.exe")
3 driver.get("https://instagram.com")
/srv/conda/envs/notebook/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
71 service_args=service_args,
72 log_path=service_log_path)
---> 73 self.service.start()
74
75 try:
/srv/conda/envs/notebook/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
81 raise WebDriverException(
82 "'%s' executable needs to be in PATH. %s" % (
---> 83 os.path.basename(self.path), self.start_error_message)
84 )
85 elif err.errno == errno.EACCES:
WebDriverException: Message: 'C:\Program Files\Google\Chrome\Application\chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Related

Selenium Webdriver cannot connect to service in Arch Linux

Ok so this is in both chrome and firefox. I have:
$ ls -l /usr/local/bin/
-rwxr-xr-x 1 root root 11808880 Nov 26 22:04 chromedriver
-rwxr-xr-x 1 root root 6162368 Nov 26 18:08 geckodriver
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
I am running this under python2.7 I installed selenium via pip2, python2.7 by pacman (there are other libraries I need that have not made it to python 3 yet, stay focused). In idle2 I am getting:
>>> from selenium import webdriver
>>> browser = webdriver.Chrome()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
browser = webdriver.Chrome()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service chromedriver
>>> browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service /usr/local/bin/chromedriver
>>> import selenium.webdriver.chrome.service as service
>>> s = service.Service('/usr/local/bin/chromedriver')
>>> s.start()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
s.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service /usr/local/bin/chromedriver
I also tried, taking a version of chromedriver into my home directory and pointing to it, then changing ownership to myself, both were no goes, the same issue exist for geckodriver, same errors, I am very confused as to what the hubbub is here, I did:
>>> browser = webdriver.Chrome(executable_path="/home/me/chromedriver", service_args=["--verbose", "--log-path=/home/me/chrome.log"])
Same, error and it produced an empty log file, it never produced one prior and the geckodriver.log was always empty.

OSError: [Errno 2] No such file or directory. Files already present in the current directory

I am trying to run execute this command through python subprocess. My current directory contains folder splitta103 which has both the sbd.py file and model_nb folder.
python splitta103/sbd.py -m splitta103/model_nb info.txt
This is my python program
file = 'info.txt'
print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb',file]))
Here is the error
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-27-743654b05145> in <module>()
12 text_file = 'info.txt'
13
---> 14 print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb','info.txt']))
15 #print(subprocess.check_output(['sbd.py','-m','model_nb','info.txt']))
16
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
210 if 'stdout' in kwargs:
211 raise ValueError('stdout argument not allowed, it will be overridden.')
--> 212 process = Popen(stdout=PIPE, *popenargs, **kwargs)
213 output, unused_err = process.communicate()
214 retcode = process.poll()
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
388 p2cread, p2cwrite,
389 c2pread, c2pwrite,
--> 390 errread, errwrite)
391 except Exception:
392 # Preserve original exception in case os.close raises.
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1023 raise
1024 child_exception = pickle.loads(data)
-> 1025 raise child_exception
1026
1027
OSError: [Errno 2] No such file or directory
This: print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb','info.txt']))
Would look like: splitta103 / sbd.py -m splitta103 / model_nb info.txt on the command line.
This on the command line: python splitta103/sbd.py -m splitta103/model_nb info.txt
Can be produced with this: ['python', 'splitta103/sbd.py', '-m', 'splitta103/model_nb', 'info.txt']

No such file or directory when running an ffmpeg command from script

I have been trying to run this ffmpeg command from python script to generate video of certain length from a static image but I keep getting No such file or directory error!
Here is my code:
import subprocess
def generate_white_vid (duration):
ffmpeg_create_vid_from_static_img = 'ffmpeg -loop 1 -i /same_path/WhiteBackground.jpg -c:v libx264 -t %f -pix_fmt yuv420p -vf scale=1920:1080 /same_path/white_vid2.mp4' % duration
print ffmpeg_create_vid_from_static_img
pp = subprocess.Popen(ffmpeg_create_vid_from_static_img)
pp.communicate()
generate_white_vid(0.5)
However when I run the same exact command:
ffmpeg -loop 1 -i /same_path/WhiteBackground.jpg -t 0.500000 -pix_fmt yuv420p -vf scale=1920:1080 /same_path/white_vid2.mp4
from the cli, it works just fine. Where am I missing up?
Here is the full trace:
Traceback (most recent call last):
File "gen.py", line 10, in <module>
generate_white_vid(0.5)
File "gen.py", line 7, in generate_white_vid
pp = subprocess.Popen(ffmpeg_create_vid_from_static_img)
File "/home/ubuntu/anaconda2/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/home/ubuntu/anaconda2/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
When I use a list to pass the ffmpeg commands parameters as following ffmpeg_create_vid_from_static_img = ['ffmpeg', '-loop', '1', '-i', '/same_path/WhiteBackground.jpg', '-c:v', 'libx264', '-t', duration, '-pix_fmt', 'yuv420p', '-vf', 'scale=1920:1080', '/same_path/white_vid.mp4'] , I get a type error:
TypeError Traceback (most recent call last)
<ipython-input-137-4a9e12e42310> in <module>()
----> 1 generate_white_vid(0.5)
<ipython-input-136-edfbfc017557> in generate_white_vid(duration)
3 ffmpeg_create_vid_from_static_img = ['ffmpeg', '-loop', '1', '-i', '/home/ubuntu/matar/multispectral/WhiteBackground.jpg', '-c:v', 'libx264', '-t', duration, '-pix_fmt yuv420p', '-vf', 'scale=1920:1080', '/home/ubuntu/matar/multispectral/white_vid.mp4']
4 print ffmpeg_create_vid_from_static_img
----> 5 pp = subprocess.Popen(ffmpeg_create_vid_from_static_img)
6 pp.communicate()
/home/ubuntu/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
388 p2cread, p2cwrite,
389 c2pread, c2pwrite,
--> 390 errread, errwrite)
391 except Exception:
392 # Preserve original exception in case os.close raises.
/home/ubuntu/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1022 raise
1023 child_exception = pickle.loads(data)
-> 1024 raise child_exception
1025
1026
TypeError: execv() arg 2 must contain only strings
Since shell=False is the default value for Popen, you would normally need to construct the command line as a separate list of elements (which is more secure by the way).
However, in case when you just want to pass your command as a string, then a mandatory shell=True would be required.

Interrupting Flask app in iPythonNotebook cause ZMQerror [duplicate]

This question already has answers here:
Running Flask from IPython raises SystemExit
(4 answers)
Why does running the Flask dev server run itself twice?
(7 answers)
Closed 1 year ago.
I'm trying to run a most simple demo of flask app in an iPython notebook like this.
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():.
return 'Hello World!'
if __name__ == '__main__':
app.run(d)
The first time I run it, all is fine. Then I interrupted the cell with app.run() in it. But the next time I run it, the notebook throws back some error message like this:
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
Then I %tbed and get the following traceback:
SystemExit Traceback (most recent call last)
<ipython-input-7-a59dfe133898> in <module>()
----> 1 myapp.run(debug=True)
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\flask\app.pyc in run(self, host, port, debug, **options)
770 options.setdefault('use_debugger', self.debug)
771 try:
--> 772 run_simple(host, port, self, **options)
773 finally:
774 # reset the first request information if the development server
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\serving.pyc in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
688 from ._reloader import run_with_reloader
689 run_with_reloader(inner, extra_files, reloader_interval,
--> 690 reloader_type)
691 else:
692 inner()
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\_reloader.pyc in run_with_reloader(main_func, extra_files, interval, reloader_type)
248 reloader.run()
249 else:
--> 250 sys.exit(reloader.restart_with_reloader())
251 except KeyboardInterrupt:
252 pass
SystemExit: 1
Not telling me much so I looked at the cmd where I started iPython and see this:
Traceback (most recent call last):
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\__main__.py", line 3, in <module>
app.launch_new_instance()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\traitlets\config\application.py", line 588, in launch_instanceapp.initialize(argv)
File "<decorator-gen-122>", line 2, in initialize
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\tra
itlets\config\application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 375, in initialize
self.init_sockets()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 231, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 173, in _bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "zmq/backend/cython/socket.pyx", line 489, in zmq.backend.cython.socket.S
ocket.bind (zmq\backend\cython\socket.c:4824)
File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc.
_check_rc (zmq\backend\cython\socket.c:7055)
raise ZMQError(errno)
ZMQError: Address in use
Seems iPython notebook server didn't handle my interruption properly. But when I tried to look for the ghost process, which listens to port 5000, I got nothing. I guess a reboot may most probably fix everthing, but just wondering if there's a fix that does not require a reboot?
Set debug=False
app.run(debug=False)

python Error:Exception in thread Thread-18:

following Error occure in myscript.my system anaconda folder threading.py file exist but error line 810 does not exist.plz suggest proper solution
Exception in thread Thread-18:
Traceback (most recent call last):
File "C:\Anaconda\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\Anaconda\lib\threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Anaconda\lib\site-packages\envoy\core.py", line 32, in target
File "C:\Anaconda\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Anaconda\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
followind code error occure
AttributeError Traceback (most recent call last)
in ()
8 F='resources/ch06-mailboxes/data/enron.mbox.json.bz2'
9 r = envoy.run("bunzip2 %s" % (F,)) --->this line error occured
10 print r.std_out
11 print r.std_err
C:\Anaconda\lib\site-packages\envoy\core.py in run(command, data, timeout)
166
167 cmd = Command(c)
168 out, err = cmd.run(data, timeout) --->this line error occured
169
170 r = Response(process=cmd)
C:\Anaconda\lib\site-packages\envoy\core.py in run(self, data, timeout)
51 self.process=process;
52 thread.join()
53 self.returncode = self.process.returncode ---->this line error occured
54 return self.out, self.err
55
AttributeError: 'NoneType' object has no attribute 'returncode'
The message as such is fairly self-explanatory: "The system cannot find the file specified". I would recommend you do verify you provided the correct directory route to the script.
It would be good also for you to provide more context on the error per se. Is error the thread longer?, can you show the original code creating the error?