Chromedriver Manager download doesn't work after .exe conversion via PyInstaller - python-3.x

Dear Stackoverflow community,
I am using Selenium and Python to automate a task. When my program runs as myscript.py, it works seamlessly. I am converting myscript.py to myscript.exe using:
PyInstaller --onefile --windowed --icon="icon.ico" --add-data "icon.ico;." myscript.py
The resulting myscript.exe file does not work, giving the following error:
Traceback (most recent call last):
File "myscript.py", line 155, in <module>
File "myscipt.py", line 32, in main
File "webdriver_manager\chrome.py", line 39, in install
File "webdriver_manager\core\manager.py", line 30, in _get_driver_path
File "webdriver_manager\core\download_manager.py", line 28, in download_file
File "webdriver_manager\core\http.py", line 35, in get
File "webdriver_manager\core\utils.py", line 289, in show_download_progress
File "tqdm\std.py", line 1109, in __init__
File "tqdm\std.py", line 1361, in refresh
File "tqdm\std.py", line 1509, in display
File "tqdm\std.py", line 350, in print_status
File "tqdm\std.py", line 343, in fp_write
File "tqdm\utils.py", line 89, in __getattr__
AttributeError: 'NoneType' object has no attribute 'write'
Line 32 in main is:
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
I am probably missing something fundamental. Any help from the community is greatly appreciated.

The issue is that webdriver_manager uses tqdm to show a progress bar in the terminal during the show_download_progress function, however since you are using the --windowed option with pyinstaller your program isn't run with a terminal. So when tqdm tries to show the progress bar there is nothing to write to, which is why it says NoneType object has no attribute 'write'.
This can be typically be solved by explicitly setting stdout and stderr to an object with a write method near the entrypoint to your application so they are set before any other code attempts to write to them.
For example:
import io
import sys
buffer = io.StringIO()
sys.stdout = buffer
sys.stderr = buffer

Related

problems installing sqlite and python on freebsd

This is driving me crazy! Any help you can provide will be most welcome!
I have a python3/sqlite application (running in a virtual environment) that is working fine on debian. I need to install it on freebsd (running in a virtual environment). I have installed python3 and sqlite (I can open a .sqlite file from the command line).
When I try to run the python script, I get the following error:
(venv) [jordan#webServer ~/crons/powerwall]$ python3 main.py
Traceback (most recent call last):
File "/usr/home/jordan/crons/powerwall/main.py", line 78, in <module>
run()
File "/usr/home/jordan/crons/powerwall/main.py", line 33, in run
database.load_db(config_mgr=config)
File "/usr/home/jordan/crons/powerwall/database.py", line 108, in load_db
db = PowerWallDb(cfg_mgr=config_mgr)
File "/usr/home/jordan/crons/powerwall/database.py", line 94, in __init__
super().__init__(cfg_mgr=cfg_mgr, section=section)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 77, in __init__
self._connect_sqlite(self.sqlite_file, check_same_thread=False)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 99, in _connect_sqlite
self._connect_uri(uri, **kwargs)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 95, in _connect_uri
self.connection = sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(uri, **kwargs)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 1105, in connectionForURI
conn = connCls.connectionFromURI(uri)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 154, in connectionFromURI
return cls._connectionFromParams(*cls._parseURI(uri))
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 122, in _connectionFromParams
return cls(filename=path, **args)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 64, in __init__
raise ImportError(
ImportError: Cannot find an SQLite driver, tried supersqlite,pysqlite2,sqlite3,sqlite
Exception ignored in: <function DBAPI.__del__ at 0x8029c1310>
Traceback (most recent call last):
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 704, in __del__
self.close()
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 217, in close
if self._memory:
AttributeError: 'SQLiteConnection' object has no attribute '_memory'
You have to install py-sqlite3 which is the "Standard Python binding to the SQLite3 library"
Install From Ports:
cd /usr/ports/databases/py-sqlite3/ && make install clean
Install From pkg:
pkg install databases/py-sqlite3
Basically, it looks like the standard Python bindings for SQLite is a separate package on FreeBSD (perhaps, on all *nix/*BSD). So, in general, there are three components, which you need, Python, SQLite (this one may not be actually necessary for Python) AND the standard Python bindings for SQLite. I have not worked with FreeBSD, but based on Googling, have you tried installing this https://pkgs.org/download/py39-sqlite3 maybe?

ModuleNotFoundError: No module named 'winreg' on Mac? (But winreg is a windows thing)

I am receiving the following error when I try to run a django shell. I am on a Mac though and everything that I can find says that this is associated with Windows and that winreg should be installed by default. Suggestions as to what I should be looking at?
Traceback (most recent call last):
File "/Users/j/code/myproject/core/manage.py", line 22, in <module>
main()
File "/Users/j/code/myproject/core/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/shell.py", line 127, in handle
exec(sys.stdin.read(), globals())
File "<string>", line 5, in <module>
ModuleNotFoundError: No module named 'winreg'
Between when I had a working env and the env producing the error I made a lot of changes to a script that I was working on including installing packages and adding modules.
When I tried to run the script I received the error above.
In the comments, Iain asked for the command I was running and then the contents of the script. Out of all the things I was looking at -- I ignored this, because was certain it was something I installed, not the file I was working on.
At the top of the file, I found this line in the imports:
from winreg import FlushKey
^^ My best guess is that this was accidentally added while I was quickly moving across the keyboard too quickly and I didn't noticed and pressed some sort of key combo that added it.
This is a first. 🫣

How to assort files of an executable python3 program made with cx_freeze?

I developed a project in python 3.4.1 and pyqt4. Then I converted my python program to executable file using cx_freeze module.
Everything is perfectly fine, but I found two problems here:
Size of program gets really high.
I like to assort my files in special folders by their format type, for example all of the .dll files in a folder called DLL and something like that, but when I do this I ran into some problems.
Is it really possible ? If yes give me some information and if no, what can I do to solve my problems. Thanks
Error I get :
cx_Freeze: Python error in main script
Traceback (most recent call last): File
"C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line
27, in
exec(code, m.dict) File "MY APP.py", line 1, in File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 2237, in
_find_and_load File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 2226, in
_find_and_load_unlocked File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 1191, in
_load_unlocked File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 1161, in
_load_backward_compatible File "ExtensionLoader_PyQt4_QtCore.py", line 22, in File "ExtensionLoader_PyQt4_QtCore.py", line
21, in bootstrap ImportError: No module named PyQt4.QtCore

Convert IPython notebook to PDF

I have written a very long IPython notebook and need to convert it to PDF for distribution. I've read this thread but the solution didn't work for me.
I've tried the following:
If I use the Print button in my browser, I have all the IPython menu
etc. showing, which I can't accept.
If I use Print Preview from the IPython menu, none of the LaTeX equations render. They are all still just LaTeX code.
If I use ipython nbconvert --to latex --post pdf myfile.ipynb I get a FileNotFoundError. Traceback follows:
[NbConvertApp] Using existing profile dir: 'C:\\Users\\blokeley\\.ipython\\profile_default'
[NbConvertApp] Converting notebook myfile.ipynb to latex
[NbConvertApp] Support files will be in myfile_files\
[NbConvertApp] Loaded template article.tplx
[NbConvertApp] Writing 72246 bytes to myfile.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running pdflatex 3 times: ['pdflatex', 'myfile.tex']
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\ipython-script.py", line 5, in <module>
sys.exit(start_ipython())
File "C:\Anaconda3\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "C:\Anaconda3\lib\site-packages\IPython\config\application.py", line 564,
launch_instance
app.start()
File "C:\Anaconda3\lib\site-packages\IPython\terminal\ipapp.py", line 367, in start
return self.subapp.start()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 268, in start
self.convert_notebooks()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 311, in convert_notebooks
self.postprocessor(write_resultes)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\base.py",
line 28, in __call__
self.postprocess(input)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 140, in postprocess
cont = self.run_latex(filename)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 104, in run_latex
self.latex_count, log_error)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 84, in run_command
p = subprocess.Popen(command, stdout=stdout, stdin=null)
File "C:\Anaconda3\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Anaconda3\lib\subprocess.py", line 1111, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
I'm using the latest updates from Anaconda in Python 3.4 64-bit on Windows 7 Professional.
Your issue is that you do not have LaTeX installed on your computer. When subprocess tries to call pdflatex myfile.tex it therefore fails as it cannot find pdflatex.
Whilst it's true that you can create .tex files from IPython notebooks without needing LaTeX, these are just files that contain the LaTeX code. To compile them to create PDFs you need a version of LaTeX.
Installing LaTeX on Windows is not difficult, MiKTeX is one possible installation.

cx_freeze doesn't work in my script

I freeze a script using cx_freeze (4.3.1) in python 3.4.
The script works perfectly running in IDLE. It uses tkinter, re, and reportlab to create a pdf form.
Then the following error occurrs when I run the exe.
PS C:\Python34\build\exe.win32-3.4> .\CREEPING_cx_freeze.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "CREEPING_cx_freeze.py", line 6, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2203, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
AttributeError: 'module' object has no attribute '_fix_up_module'
It looks like everything is working. Everything is created in the build folder, but the compiled executable does not work.
I tried searching for a solution but did not find any. Could somebody help me with this?
I´m using win 8 64 bits
Wrong version installed.
pip installs 64 bits but it doesn,t work.
running the 32bits version...works

Resources