FileNotFoundError: while converting .py to exe file - python

I'm trying to convert my py file to exe after when I run the exe file it always shows the same error on console windows
Traceback (most recent call last):
File "njlispendens.py", line 482, in <module>
File "selenium_stealth\__init__.py", line 45, in stealth
File "selenium_stealth\utils.py", line 8, in with_utils
File "pathlib.py", line 1132, in read_text
File "pathlib.py", line 1117, in open
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\alium\\AppData\\Local\\Temp\\_MEI93442\\selenium_stealth\\js\\utils.js'
[9744] Failed to execute script 'njlispendens' due to unhandled exception!
[10772:940:0102/104425.600:ERROR:chrome_browser_main_extra_parts_metrics.cc(226)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[10772:6564:0102/104425.600:ERROR:device_event_log_impl.cc(214)] [10:44:25.611] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[10772:940:0102/104425.616:ERROR:chrome_browser_main_extra_parts_metrics.cc(229)] crbug.com/1216328: Checking Bluetooth availability ended.
[10772:940:0102/104425.616:ERROR:chrome_browser_main_extra_parts_metrics.cc(232)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
[10772:940:0102/104425.709:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status ended.
Here is what I did to deal with the error
tried uninstalling packages and installing them again and then converting it into exe
tried Pyinstaller single and multiple file
adding python to path
tried using auto-py-to-exe to for conversion
tried uninstalling python, removing from path, installing python again
please help

Related

'Googlechrome' not on PATH despite my best efforts

I am following this tutorial on web scraping https://www.linkedin.com/pulse/how-easy-scraping-data-from-linkedin-profiles-david-craven/. The python script is generating errors and I've already tried adding the directory to the PATH and it shows when I echo the path to the screen, but now it shows "/Users/owner/Users/owner" when there should just be one "Users/owner" in the path.
I'm using bash inside mac os High Sierra and am a data science major so DevOps​ is a challenge for me as well as learning how to post code to StackOverflow but I'm trying to document my steps so it will be easier to troubleshoot this.
I pip installed selenium
I downloaded chromedriver to the directory for my webscraping script file and double clicked it to run
I thought I added the directory to my PATH with 'export PATH=$PATH:~opt/bin:~/Users/owner/sbox/test/pandas_sqlite_dbase/chromedriver' which are the directions I found from http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/
I updated PIP
The directory I want to run the script from is '/Users/owner/sbox/test/pandas_sqlite_dbase'
There was another SO post Can a website detect when you are using selenium with chromedriver? that talked about how chromedriver with selenium was now auto detected and disabled... so am I trying to scrape with an outdated code base?
I can post my whole PATH or give other info.
from selenium import webdriver
driver = webdriver.Chrome('~/Users/owner/sbox/test/pandas_sqlite_dbase/googlechrome')
driver.get('https://www.linkedin.com')
Now I am getting a traceback error
Traceback (most recent call last):
File "/Users/owner/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Users/owner/anaconda3/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Users/owner/anaconda3/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '~/Users/owner/sbox/test/pandas_sqlite_dbase/googlechrome': '~/Users/owner/sbox/test/pandas_sqlite_dbase/googlechrome'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/owner/sbox/test/pandas_sqlite_dbase/scraping_tutorial.py", line 7, in <module>
driver = webdriver.Chrome('~/Users/owner/sbox/test/pandas_sqlite_dbase/googlechrome')
File "/Users/owner/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/owner/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'googlechrome' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
[Finished in 0.7s with exit code 1]
[shell_cmd: python -u "/Users/owner/sbox/test/pandas_sqlite_dbase/scraping_tutorial.py"]
[dir: /Users/owner/sbox/test/pandas_sqlite_dbase]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
I would check what ~ actually is (seems you have the concept bad) usually is home dir, so, for a user, your "Users/owner", that's why you are obtaining "Users/owner/Users/owner".
To check this, you can
$>cd ~
$>pwd

Python Pyinstaller GUI Tkinter Selenium

I did not know how to create an executable python program before I asked here. Thankfully I received a fast answer and was able to convert my script to an executable program. The executable works perfect but only on my computer.
These are the two error's I am receiving, I feel like I need to modify the script in order to locate the chrome driver I am not sure where Pyinstaller saved everything.
Exception in Tkinter callback
Traceback (most recent call last):
File "site-packages\selenium\webdriver\common\service.py", line 76, in start
File "subprocess.py", line 775, in __init__
File "subprocess.py", line 1178, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tkinter\__init__.py", line 1705, in __call__
File "MarijuanaDoctors.py", line 25, in search
File "site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
File "site-packages\selenium\webdriver\common\service.py", line 83, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver'
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
You can bundle your "chromedriver.exe" along with your script using Pyinstaller like this:
pyinstaller --add-binary="localpathtochromedriver;." myscript.py
This will copy the "chromedriver.exe" file in the same folder as your main .exe(Or in case of single file option of pyinstaller, this fill will be extracted in temp folder while using exe program).
In your script you can check if you are running the script normally or from bundled(exe file) mode, and choose path to chromedriver.exe accordingly.(This change in script can be common for Single file/folder bundle option of pyinstaller)
import sys
if getattr(sys, 'frozen', False ):
#Running from exe, so the path to exe is saved in sys._MEIPASS
chrome_driver = os.path.join(sys._MEIPASS, "chromedriver.exe")
else:
chrome_driver = 'localpathtochromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)
You can read about this in docs here.
Limitation:
The user of your .exe should have Chrome installed on their system and Chrome version should work with the chromedriver which is bundled.

Filebeat prevents python rotating log from rotating files in windows os

Environment:
win 10
python 2.7
Filebeat 5.1.1
My application writes logs with Rotating log handler. When I start Filebeat I start getting the following exceptions from logging lib.
Traceback (most recent call last):
File “C:\Anaconda2\Lib\logging\handlers.py”, line 77, in emit
self.doRollover()
File “C:\Anaconda2\Lib\logging\handlers.py”, line 142, in
doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 183] Cannot create a file when that file already
exists
How can I resolve it?
Posting my resolution.
In Filebeat docs - written if you have problems with rotating logs in windows you should use:
close_renamed: true
close_removed: true
I tried it but it didn't work due to the wrong indentation in config.
fixed it and now I don't have any issue.

Unable to run the default python app after installing Google App Engine

I see the following error in the log file:
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.pyc", line 486, in __bootstrap_inner
File "launcher\taskthread.pyc", line 65, in run
File "subprocess.pyc", line 594, in __init__
File "subprocess.pyc", line 816, in _execute_child
WindowsError: [Error 5] Access is denied
WindowsError: [Error 5] Access is denied
In Windows I used to see this error myself after installing Google App Engine SDK for PHP. This error occured when gae could not find the PHP executable.
The thing was I was specifying the absolute path to the folder that contained php-cgi.exe, leaving out the name of the executable php-cgi.exe! I solved this problem by adding the name of tyhe executable as well. So you might want to take a look again at your absolute path and make corrections.
from the docs:
Start the web server with the following command, giving it the path to
your project directory:
google_appengine/dev_appserver.py --php_executable_path=absolute-path-to-php-cgi.exe myproject/
Hope it helps,

WebDriver Firefox profile not working after IEDriverServer setup

I've been using webdriver.Firefox() for my test cases, but wanted to test on IE. I downloaded IEDriverServer, added it to my PATH and ran the IE test case successfully. However, when I then tried switching back to Firefox and running the same test case, the Firefox browser opened up, but nothing happened, and then I received this error:
C:\Python33\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py:85:
ResourceWarning: unclosed <socket.socket object, fd=280, family=2, type=1, proto=0>
while not utils.is_connectable(self.profile.port):
C:\Python33\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py:85:
ResourceWarning: unclosed <socket.socket object, fd=532, family=2, type=1, proto=0>
while not utils.is_connectable(self.profile.port):
E
======================================================================
ERROR: test_ytest (__main__.Ytest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\K\workspace\PythonTesting\src\RecipeTest.py", line 11, in setUp
self.driver = webdriver.Firefox()
File "C:\Python33\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 61, in __init__
self.binary, timeout),
File "C:\Python33\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python33\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 51, in launch_browser
self._wait_until_connectable()
File "C:\Python33\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 95, in _wait_until_connectable
self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: "Can't load the profile. Profile Dir: c:\\users\\k\\appdata\\local\\temp\\tmp0vf9hl Firefox output: b'*** LOG addons.xpi: startup\\r\\n*** LOG addons.xpi: Skipping unavailable install location app-system-local\\r\\n*** LOG addons.xpi: Skipping unavailable install location app-system-share\\r\\n*** WARN addons.xpi: Ignoring missing add-on in C:\\\\Program Files (x86)\\\\Wajam\\\\Firefox\\\\{5a95a9e0-59dd-4314-bd84-4d18ca83a0e2}.xpi\\r\\n*** LOG addons.xpi: checkForChanges\\r\\n*** LOG addons.xpi: No changes found\\r\\n'"
----------------------------------------------------------------------
Ran 1 test in 35.208s
FAILED (errors=1)
I've removed the PATH to IEDriverSetup and went so far as to remove it. I restarted Eclipse (I'm using it to run my Python/WebDriver tests) and restarted IE and Firefox to no avail.
Any help is appreciated.
EDIT
I am using Python 3.3 to develop my test cases, if that makes a difference.
Is there a __pycache__ directory among your files?
I removed it. No error once it is removed.
PS. python 3.3.2

Categories