I can find many questions related to the module PIL not found, with solutions. I tried many that I thought were applicable to me. BUt I still have no luck :(
My problem is this:
I have a project that shows current NAV of a portfolio using a KivyMD MDDataTable. The portfolio information is read from a PDF file using using MDFileManager and using tabula and panda, the file is parsed. Then market data is obtained from relevant markets and NAV is calculated. This then is displayed using MDDatatable. I am using python 3.8, kivy 2.0.0rc4, and kivyMD 0.104.1. I can run this from the IDE and works beautifully. The problem is when running on my android phone
I use buildozer to create the apk file. The app starts, the splash screen is displayed and then it shuts off. logcat output shows this error which I believe is the reason as the first screen in the app uses filemanager( MDFileManager instance)
> 2020-10-24 13:13:54.517 24104-24183/? I/python: Traceback (most recent call last):
> 2020-10-24 13:13:54.518 24104-24183/? I/python: File "/home/tksrajan/dev/mark2market/.buildozer/android/app/main.py", line
> 8, in <module>
> 2020-10-24 13:13:54.519 24104-24183/? I/python: File "/home/tksrajan/dev/mark2market/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/mark2market/kivymd/uix/filemanager.py",
> line 119, in <module>
> 2020-10-24 13:13:54.520 24104-24183/? I/python: ModuleNotFoundError: No module named 'PIL'
> 2020-10-24 13:13:54.520 24104-24183/? I/python: Python for android ended.
Thanks for any help in advance.
This problem is in the latest released version of kivyMD 0.104.1. The import of PIL in filemanager.py is superfluous and does nothing. You can fork the repo, remove the import and and use the modified repo. This solves the problem. The master branch of kivyMD has already removed this import. So next release will fix the problem permanently
Related
Problem
My application works well when in python-only and on my machine. I am attempting to deploy to a machine which has lesser privileges.
The basic script that I am attempting to run at the moment:
import logging
import os
os.environ['PYUSB_DEBUG'] = 'debug'
os.environ['PYUSB_LOG_FILENAME'] = 'C:\\path\to\log.txt'
logging.basicConfig(level=logging.DEBUG)
import usb.core
import usb.util
devices = [d for d in usb.core.find(find_all=True,
idVendor=0x0683,
idProduct=0x2008
)]
[print(d) for d in devices]
device = devices[0]
device.set_configuration()
The imports are a bit out of whack in this example file because the os.environ variable must be set before usb import or the logging won't be set up properly to get my log.txt from the usb module.
From Python
When I execute the above script on my machine, this is the resulting log.txt:
2022-05-13 06:50:02,760 DEBUG:usb.backend.libusb1:_LibUSB.__init__(<WinDLL 'C:\WINDOWS\system32\libusb-1.0.dll', handle 7ff8476e0000 at 0x20a622c18b0>)
2022-05-13 06:50:02,760 DEBUG:usb.backend.libusb1:_LibUSB.__init__(<WinDLL 'C:\WINDOWS\system32\libusb-1.0.dll', handle 7ff8476e0000 at 0x20a622c18b0>)
2022-05-13 06:50:02,766 INFO:usb.core:find(): using backend "usb.backend.libusb1"
2022-05-13 06:50:02,766 INFO:usb.core:find(): using backend "usb.backend.libusb1"
2022-05-13 06:50:02,767 DEBUG:usb.backend.libusb1:_LibUSB.enumerate_devices()
...
...(more logs past this point, but you can see that the core found the backend)
From pyinstaller executable
I am bundling using pyinstaller. I normally like to use --onefile, but I always verify functionality without --onefile. I am only doing the most basic build: pyinstaller --noconfirm path/to/script.py
The console error:
Traceback (most recent call last):
File "usb\backend\libusb0.py", line 738, in get_backend
File "Lib\site-packages\_pyinstaller_hooks_contrib\hooks\rthooks\pyi_rth_usb.py", line 57, in _load_libraryOSError: USB library could not be found
Traceback (most recent call last):
File "backend_test.py", line 15, in <module>
File "usb\core.py", line 1309, in find
usb.core.NoBackendError: No backend available
[9344] Failed to execute script backend_test
Note that the USB library failed to find a backend.
The fail log.txt when attempted to run the executable:
Traceback (most recent call last):
File "usb\backend\libusb0.py", line 738, in get_backend
File "Lib\site-packages\_pyinstaller_hooks_contrib\hooks\rthooks\pyi_rth_usb.py", line 57, in _load_library
OSError: USB library could not be found
2022-05-13 06:20:59,838 ERROR:usb.backend.libusb1:Error loading libusb 1.0 backend
Traceback (most recent call last):
File "usb\backend\libusb1.py", line 961, in get_backend
File "Lib\site-packages\_pyinstaller_hooks_contrib\hooks\rthooks\pyi_rth_usb.py", line 57, in _load_library
OSError: USB library could not be found
2022-05-13 06:20:59,840 ERROR:usb.backend.openusb:Error loading OpenUSB backend
Traceback (most recent call last):
File "usb\backend\openusb.py", line 745, in get_backend
File "Lib\site-packages\_pyinstaller_hooks_contrib\hooks\rthooks\pyi_rth_usb.py", line 57, in _load_library
OSError: USB library could not be found
2022-05-13 06:20:59,842 ERROR:usb.backend.libusb0:Error loading libusb 0.1 backend
Traceback (most recent call last):
File "usb\backend\libusb0.py", line 738, in get_backend
File "Lib\site-packages\_pyinstaller_hooks_contrib\hooks\rthooks\pyi_rth_usb.py", line 57, in _load_library
OSError: USB library could not be found
At the moment, I can tell that the failure is occurring in a pyinstaller hook. I don't understand precisely how this works, so the clue may be found somewhere in there.
Background & Research
Versioning
libusb==1.0.24b3
pyinstaller==4.3
pyinstaller-hooks-contrib==2022.4
pyusb==1.2.1
... (there is more, but I suspect that these are the critical-to-function packages)
libusb
Not sure why this installed the beta version. Interesting, but doesn't appear to be the smoking gun.
pyinstaller
Note that pyinstaller==4.3 is a bit out of date. This is a result of my overambitious IT department's antivirus. It doesn't appear to want to allow more recent versions of pyinstaller to build executables.
pyinstaller-hooks-contrib
This is a repository which contains several pyinstaller hooks. I know that these are "critical to function" for lots of modules, but I don't really know how this works. It is possible, even likely given that this is where something is failing, that my problem lies within this library OR with this library's interaction with the version of pyinstaller that I'm using. Version 2022.4 is the version that is installed when I python -m pip install pyinstaller.
pyusb
Current version.
Other Attempts Thus Far
I have been up and down the web and have spent a particularly long time with the SO question Pyusb on windows - no backend available. Many of the below attempts were based on that SO question, but there have been other sources as well.
There are more attempts than just these, but I have been at it long enough that I don't remember them all!
Bundling libusb-1.0.dll into Executable
It is possible to bundle dll files directly with the pyinstaller-created script using the datas directive. This was my first attempt and it worked... on my machine. As soon as I deployed, the script failed with a PermissionError. I suspect that "untrusted" dll's aren't allowed to be utilized on the target machine. My login on my machine has elevated privileges, explaining why it may have worked in my environment.
Installing libusb-win32-devel-filter.exe.
Simply didn't work.
Including C:\\Windows\\System32 on PATH
I verified that the PATH variable contained C:\\Windows\\System32, which I also verified contains the proper dll file.
Specify backend
When I modify the script to specify the backend:
...
import usb.backend.libusb1 as libusb1
be = libusb1.get_backend(find_library=lambda x: "C:\\WINDOWS\\system32\\libusb-1.0.dll")
devices = [d for d in usb.core.find(find_all=True,
idVendor=0x0683,
idProduct=0x2008,
backend=be)]
...
There is no change in behavior. I do see in the log when running in python (not pyinstaller) that the backend is immediately found:
2022-05-13 07:22:12 USBN1LPGDKWXD3 usb.backend.libusb1[6880] DEBUG _LibUSB.__init__(<WinDLL 'C:\Windows\System32\libusb-1.0.dll', handle 7ff840bd0000 at 0x190eadbe820>)
2022-05-13 07:22:12 USBN1LPGDKWXD3 usb.backend.libusb1[6880] DEBUG _LibUSB.enumerate_devices()
2022-05-13 07:22:12 USBN1LPGDKWXD3 usb.backend.libusb1[6880] DEBUG _LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x00000190EAE58EB0>)
2022-05-13 07:22:12 USBN1LPGDKWXD3 usb.backend.libusb1[6880] DEBUG _LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x00000190EAE58F40>)
...
Install libusb
No change.
Modify pyinstaller and pyinstaller-hooks-contrib versions
Tried pyinstaller==4.10 and python-hooks-contrib==2022.3, which appear to be "compatible" releases.
I would like to try to build the pyinstaller script by excluding the pyusb from pyinstaller-hooks-contrib, but I'm not sure how to do this.
Other Clues....
While looking in pyinstaller-hooks-contrib, I'm seeing the way to access DLL files is through ctypes.WinDLL.
import ctypes
print('ctypes.WinDLL', ctypes.WinDLL('libusb-1.0.dll'))
Result when running from python: <WinDLL 'libusb-1.0.dll', handle 7ff831cc0000 at 0x21076e9adf0>
Result when running from pyinstaller: ctypes.WinDLL <PyInstallerWinDLL 'libusb-1.0.dll', handle 7ff83d400000 at 0x201a9f39fa0>
I'm still not sure why this works the way that it does, but my initial instincts were correct when I had tried to include libusb-1.0.dll in the pyinstaller package. Unfortunately, there is apparently an issue with the windows implementation of the libusb-1.0.dll (I'm not making that assertion, I'm quoting another SO answer).
The answer, for me, was to add libusb0.dll to my pyinstaller build directory instead of the more recent libusb-1.0.dll:
a = Analysis(['examples\\backend_test.py'],
pathex=[],
binaries=[],
datas=[('C:\\Windows\\System32\\libusb0.dll', '.'),],
hiddenimports=[],
...])
I can't believe that it was this simple in my case, but there it is...
The form builder wxFormBuilder imports wx and wx.xrc. However the second of these causes an error as follows:
Traceback (most recent call last):
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demo.py", line 4, in
import demogui
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demogui.py", line 11, in
import wx.xrc
File "/usr/local/lib/python3.6/dist-packages/wx/xrc.py", line 10, in
from ._xrc import *
ImportError: libwx_gtk3u_html-3.0.so.0: cannot open shared object file: No such file or directory
The obvious answer would be that the file was missing, but it isn't:
peter#peter-HP-Pavilion-15-Notebook-PC:~$ locate libwx_gtk3u_html-3.0.so.0
/usr/local/lib/python3.6/dist-packages/wx/libwx_gtk3u_html-3.0.so.0
So, to my inexperienced eyes it seems to be present and in the right place. Can anyone make any suggestions on this?
I'm using wxPython for Python 3, by the way.
Many thanks
This issue was fixed in wxPython release 4.0.1, see the discussion at https://groups.google.com/forum/#!topic/wxpython-users/UBjdeTgOmD4.
The build scripts were setting LD_RUN_PATH only for the wxPython libraries, not for the embedded wxWidgets build. I can confirm that the fixes mentioned in https://github.com/wxWidgets/Phoenix/issues/723 solve the issue.
I am using Oracle VirtualBox running Ubuntu 16. I have been able to build apk files for a while until my latest build. My program will run and keep its functionality when run with python 2.7 on the same Virtual machine. When i install the .apk file on my Samsung S3 it shows the standard kivy loading screen then crashes after around 20 seconds. PLEASE HELP
I ran the latest build with verabose below is the log file.
https://drive.google.com/open?id=0B1XW1ekAndYiT2NrUTRNeHZhVGc
EDIT
After researching adb logcat i have been able to find this error. It occurs when "adb logcat" is run on a usb connected device.
I/python (29113): Traceback (most recent call last):
I/python (29113): File "/home/paul/Desktop/10/.buildozer/android/app/main.py", line 11, in <module>
I/python (29113): File "/home/paul/Desktop/10/.buildozer/android/app/_applibs/bs4/__init__.py", line 35, in <module>
I/python (29113): File "/home/paul/Desktop/10/.buildozer/android/app/_applibs/bs4/builder/__init__.py", line 315, in <module>
I/python (29113): ImportError: cannot import name _htmlparser
I/python (29113): Python for android ended.
EDIT
Line 11 in main.py is
from bs4 import BeautifulSoup as bs
I there something obvious im missing?
Turn USB Debuggin mode on in your device and connect your device to your PC and then run adb logcat. Run the application on your device and see what is going on in your application and what is the reason of crashing. you could also show us the the adb logcat result if you couldn't figure out the reason.
I'm operating on a windows 7 machine but because I don't have admin rights, I needed to use a portable version of python.
I'm following these two tutorials:
https://kivy.org/docs/installation/installation-windows.html#
https://github.com/kivy/kivy-designer
I was able to get kivy installed to my portable python path and I'm running into trouble with the 2nd tutorials
garden install filebrowser
I checked my installed modules and it says that I have kivy-garden:
['argh==0.26.1', 'docutils==0.12', 'gitdb==0.6.4', 'gitpython==1.0.1', 'jedi==0.9.0', 'kivy-garden==0.1.4', 'kivy.deps.glew== 0.1.4', 'kivy.deps.gstreamer==0.1.5', 'kivy.deps.sdl2==0.1.12', 'kivy==1.9.1', 'lxml==3.3.4', 'matplotlib==1.3.1', 'numpy==1.8.1', 'pandas==0.11.0', 'pathtools==0.1.2', 'pil==1.1.7', 'pip==8.0.2', 'py2exe==0.6.9', 'pycairo==1.8.10', 'pygame==1.9.1','pygments==2.1', 'pygobject==2.28.3', 'pygoocanvas==0.14.2', 'pygtk==2.24.0', 'pygtksourceview==2.10.1', 'pyodbc==3.0.7', 'pyparsing==2.0.1', 'pypiwin32==219', 'pyrsvg==2.32.1', 'pyserial==2.7', 'pywin32==218', 'pyyaml==3.11', 'requests==2.9.1', 'scipy==0.13.3', 'setuptools==19.4', 'six==1.10.0', 'smmap==0.9.0', 'watchdog==0.8.3', 'wheel==0.26.0']
I tried to launch the designer's main.py without the file browser and I get the following error:
Traceback (most recent call last):
File "C:\Sources\Portable_Python_2.7.6.1\kivy-designer-master\main.py", line 2, in <module>
from designer.app import DesignerApp
File "C:\Sources\Portable_Python_2.7.6.1\kivy-designer-master\designer\app.py", line 28, in <module>
from kivy.garden.filebrowser import FileBrowser
ImportError: No module named filebrowser
Which it appears I cannot do unless I install the filebrowser.
Has anyone run into this before? I don't care if I don't have a file browser, I really just want the Kivy Designer to work because I'm still learning Python GUI modeling and having a designer would make it so much easier. Many of the tutorials I've looked at talk about using the Kivy.bat, but I have searched everywhere and when you using the installation on windows, a Kivy.bat is never created.
I'm having fun with python, and would like to learn gui programming.
I installed pygtk, and gtk but I get this message when I try to import gtk:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import gtk
File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 40, in <module>
from gtk import _gtk
ImportError: DLL load failed: The specified procedure could not be found.
First I tried downloading and installing from several different sources. That didn't work, now I have Gtk+ and GTK2 Runtime folders in my program files.
I take it that these are different versions of GTK runtime?
Next I googled this, and found suggestions to make sure GTK was in my path. I've added every combination of paths to the lib and bin folders in these two directories. Still not working.
What should I try next?
Thanks.
PyGTK itself has several dependencies (cairo et al), did you install all of them?