Unexpected Error while executing imgkit - python

I'm a newbie to Python, While learning imgkit (PI module) I got this error which was not expected for a simple code. Below is the code
import imgkit
imgkit.from_url('https://www.google.co.in/','fs.jpg')
and the error which I got is
Traceback (most recent call last):
File "G:\python\lib\site-packages\imgkit-0.1.8-py3.6.egg\imgkit\config.py", line 30, in __init__
with open(self.wkhtmltoimage):
FileNotFoundError: [Errno 2] No such file or directory: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ALEXANDER\Desktop\def img.py", line 3, in <module>
imgkit.from_url('https://www.google.co.in/','fs.jpg')
File "G:\python\lib\site-packages\imgkit-0.1.8-py3.6.egg\imgkit\api.py", line 20, in from_url
rtn = IMGKit(url, 'url', options=options, toc=toc, cover=cover, config=config, cover_first=cover_first)
File "G:\python\lib\site-packages\imgkit-0.1.8-py3.6.egg\imgkit\imgkit.py", line 34, in __init__
self.config = Config() if not config else config
File "G:\python\lib\site-packages\imgkit-0.1.8-py3.6.egg\imgkit\config.py", line 36, in __init__
'http://wkhtmltopdf.org\n'.format(self.wkhtmltoimage))
OSError: No wkhtmltoimage executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - http://wkhtmltopdf.org
Could anyone tell me what mistake I have done.

you need to these lines after installing wkhtmltopdf on your windows system:
path_wkthmltoimage = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'
config = imgkit.config(wkhtmltoimage=path_wkthmltoimage)
imgkit.from_file('table.html', 'table.jpg',config=config)

try: brew install caskroom/cask/wkhtmltopdf

It looks like you need to install wkhtmltopdf. To do so, run pip install wkhtmltopdf

Related

xlwings Reports Quickstart throws errors

Just trying the quickstart described here:
https://docs.xlwings.org/en/stable/reports.html#quickstart
I've copied the small code sample and created the template sheet as described. When I run report.py, I get the following:
Traceback (most recent call last):
File "report.py", line 17, in <module>
book = app.render_template(this_dir / 'mytemplate.xlsx',
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/main.py", line 699, in render_template
return render_template(
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/pro/reports/main.py", line 439, in render_template
wb = app.books.open(output)
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/main.py", line 4988, in open
return Book(impl=self.impl.open(json=json))
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/pro/_xlremote.py", line 217, in open
book = Book(api=json, books=self)
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/pro/_xlremote.py", line 268, in __init__
if api["version"] != __version__:
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "report.py", line 20, in <module>
book.to_pdf(this_dir / 'myreport.pdf')
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/main.py", line 764, in __exit__
self.quit()
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/main.py", line 388, in quit
return self.impl.quit()
File "/home/james/dev/repos/eft/auto-reports/env/lib/python3.8/site-packages/xlwings/base_classes.py", line 50, in quit
raise NotImplementedError()
NotImplementedError
This is essentially out of the box so I can't see that I've done anything wrong. I'm running on Ubuntu 20.04.5 LTS. Python is 3.8.10. I have the follwing dependencies:
numpy==1.23.4
pandas==1.5.1
python-dateutil==2.8.2
pytz==2022.5
six==1.16.0
xlwings==0.28.2
Any suggestions? Thanks.
Traditionally, xlwings only worked on Windows or macOS with an actual installation of Microsoft Excel. More recently (in 2022) it added Linux support for xlwings Server and xlwings File Reader, but xlwings Reports still has to be run in connection with Excel, i.e., runs on Windows and macOS only. While the installation instructions mention this, I'll try to improve the docs to mark the requirements on the respective pages.

Error when trying to run OpenALPR in python

I installed OpenALPR itself fine and I was able to run it in terminal to get this result:
C:\Users\zebsu>"C:\\OpenALPR\\Agent\\bin\\alpr.exe" "C:\\plate.jpg"
plate0: 3 results
State ID: us-oh (97% confidence)
- PZ65BYV confidence: 94.5181 pattern_match: 0
- P265BYV confidence: 81.1941 pattern_match: 0
- P65BYV confidence: 81.1336 pattern_match: 0
However, I then followed the instructions found on PyPI (https://pypi.org/project/openalpr/#description) to install the openalpr python bindings with pip install openalpr. But when I run the following code that they suggest with python 3.8.6 x64:
import json
from openalpr import Alpr
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
sys.exit(1)
results = alpr.recognize_file("C:/image.jpg")
print(json.dumps(results, indent=4))
alpr.unload()
I get the following error:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libopenalpr.dll' (or one of its dependencies). Try using the full path with constructor syntax.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
And this is the error that I get if I run the code with python 3.6.8 x32:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
I've scoured all the internet forums looking for answers however most of the submissions are from years back before the openalpr bindings could be installed with pip and had to be installed from github. Does anyone have any advice?
I ended up finding the solution from the answer to a question on another thread with a similar error but with a different library: FileNotFoundError: Could not find module 'libvlc.dll'. The issue was that the program had no way to find the dll files it needed so the directory where the dll files are needs to be added to the os in the python code. For me this meant adding these lines to the top of my code:
import os
os.add_dll_directory("C:/OpenALPR/Agent/bin")
This change meant that the code ran exactly as it was supposed to.

RuntimeError: Unable to initialize SecretService: Environment variable DBUS_SESSION_BUS_ADDRESS is unset

Running into issue with keyring:
RuntimeError: Unable to initialize SecretService: Environment variable DBUS_SESSION_BUS_ADDRESS is unset
SecretService is installed.
OS is RHEL
Running:
python -c "import keyring.backends.SecretService as SS; SS.Keyring.priority"
gives the following error:
Traceback (most recent call last):
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/secretstorage/__init__.py", line 41, in dbus_init
return connect_and_authenticate()
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/integrate/blocking.py", line 70, in connect_and_authenticate
bus_addr = get_bus(bus)
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/bus.py", line 53, in get_bus
return find_session_bus()
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/bus.py", line 42, in find_session_bus
addr = os.environ['DBUS_SESSION_BUS_ADDRESS']
File "/home/webpage/.pyenv/versions/3.6.5/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'DBUS_SESSION_BUS_ADDRESS'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/backends/SecretService.py", line 37, in priority
bus = secretstorage.dbus_init()
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/secretstorage/__init__.py", line 45, in dbus_init
raise SecretServiceNotAvailableException(reason) from ex
secretstorage.exceptions.SecretServiceNotAvailableException: Environment variable DBUS_SESSION_BUS_ADDRESS is unset
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/util/properties.py", line 26, in __get__
return self.fget.__get__(None, owner)()
File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/backends/SecretService.py", line 41, in priority
"Unable to initialize SecretService: %s" % e)
RuntimeError: Unable to initialize SecretService: Environment variable DBUS_SESSION_BUS_ADDRESS is unset
How can I fix this?
Missing dependency: dbus-python
Try doing this:
dbus-run-session -- python -c "import keyring.backends.SecretService as SS; SS.Keyring.priority"
SecretService (Gnome Keyring) needs a DBUS session. If you're running on a headless server, you'll need to run the app that needs access to keyring inside a dbus session (as shown above).
Adding this to my .zshrc was the only thing that ended up working for me:
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring

win32com.client.GetActiveObject does not find App when run as an SVN post-commit hook

I created a python script (packaged as post-commit.exe) to run as an SVN post commit hook. Yes, the hook runs, but this is the line I am having problems with:
App = win32com.client.GetActiveObject("EA.App")
This issue does not happen on Windows 7, but is now happening on Windows Server 2012 R2 with the same installs:
TortoiseSVN-1.9.0.26652-x64-svn-1.9.0.msi
pywin32-220.win-amd64-py3.3.exe
python-3.3.0.amd64.msi
I used pip to explicitly install pypiwin32, but I can't tell if it actually worked or not (or if it matters). It says it's installed, but at the end of the install it gives me the following even tho I ran as admin:
PermissionError: [Errno 13] Permission denied: 'c:\\python33\\Lib\\site-packages\\pythoncom.py'
When I open this .exe it runs fine and works as expected, but when it is kicked off by the actual SVN commit, SVNTortoise gives me the error message below. I had problems with SVN deleting PATH for other lines of code, so I have also tried the full path to where EA.exe lives. I ran wmic get ProcessID and also tried what that gave me... but these do not work either:
App = win32com.client.GetActiveObject(r"C:\Program Files (x86)\Sparx Systems\EA\EA.App")
App = win32com.client.GetActiveObject(r"C:\PROGRA~2\SPARXS~1\EA\EA.App")
Any help would be greatly appreciated. I have spent a lot of time googling and searching stackoverflow for answers, but can't find anything for this specific problem. Thanks!!
SVN Error output:
post-commit hook failed (exit code -1) with output:
Traceback (most recent call last):
File "ATC_Generator.py", line 58, in <module>
File "site-packages\win32com\client\__init__.py", line 78, in GetActiveObject
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ATC_Generator.py", line 61, in <module>
File "site-packages\win32com\client\__init__.py", line 95, in Dispatch
File "site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
File "site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
Failed to execute script ATC_Generator

Install spynner in python on Windows 7

I want to install spynner in python 2.7.9, on windows 7. I have tried using 'pip' but it is giving error. Traceback:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\paramvir\appdata\local\temp\pip_build_Paramvir\autopy\setup.py", line 222, in <
module>
EXT_MODULES = create_ext_modules('src/')
File "c:\users\paramvir\appdata\local\temp\pip_build_Paramvir\autopy\setup.py", line 180, in c
reate_ext_modules
raise IOError('windows directory not found at: "%s"' % win_dir)
IOError: windows directory not found at: "c:\users\paramvir\appdata\local\temp\pip_build_Paramvi
r\autopy\windows\win32"
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\paramvir\appdata\local\temp\pip_build_Paramvir\autopy\setup.py", line 222, in <modu
le>
EXT_MODULES = create_ext_modules('src/')
File "c:\users\paramvir\appdata\local\temp\pip_build_Paramvir\autopy\setup.py", line 180, in creat
e_ext_modules
raise IOError('windows directory not found at: "%s"' % win_dir)
IOError: windows directory not found at: "c:\users\paramvir\appdata\local\temp\pip_build_Paramvir\au
topy\windows\win32"
how do I install spynner? Thanks
i recently got the same error as you are , and i fix it without using the pip command
download the spynner zip file and unzip to the C:\Anaconda\Lib\site-packages
here is the link:
https://pypi.python.org/pypi/spynner
download the autopy file and install the windows installer
https://pypi.python.org/pypi/autopy/0.51

Categories

Resources