moduleerror pil not found - python

when i run my program in python it works but when i use pyinstaller it doesnt work. my app (login.py) imports another file (app.py) which imports PIL
even though i use hidden import to import PIL, i get this when i launch the exe
Traceback (most recent call last):
File "login.py", line 5, in
from app import App
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "app.py", line 2, in
from PIL import Image, ImageTk
ModuleNotFoundError: No module named 'PIL'
can anyone please help

You should use import Image or from PIL import Image instead of import PIL, as you can check in this answer.

Related

Pyinstaller : .exe file doesn't work the same way as in IDE

I have written a python script, using eel for the GUI, that converts & does some calculations on files in a folder. For this, i am using a python library called asammdf. The code works well in an IDE but when i use pyinstallerand create a .exe file the code doesn't seem to work the same way.
import eel
from pathlib import Path
from asammdf import MDF
from pathlib import Path
import glob
import sys
import os
from datetime import timedelta
eel.init("path\to\folder\Python")
def python_code():
# a python script that uses asammdf
#eel.expose
I have tried copying the asammdf directory into the python folder and pyinstaller seems to include it in the .exe dist folder but still it doesn't work. Can anyone help me out please?
The error message comes as --
asammdf\mdf.py:4597: UserWarning: The argument `ignore_invalid_signals` from the method `extract_bus_logging` is no longer used and will be removed in the future
Traceback (most recent call last):
File "eel\__init__.py", line 281, in _process_message
File "converterrxd_csv.py", line 79, in pythoncode
File "asammdf\mdf.py", line 4625, in extract_bus_logging
File "asammdf\mdf.py", line 4666, in _extract_can_logging
File "asammdf\blocks\utils.py", line 1807, in load_can_database
File "canmatrix\formats\__init__.py", line 71, in loadp
File "canmatrix\formats\__init__.py", line 86, in load
KeyError: 'canmatrix.formats.dbc'
I tried installing the can-matrix package as well but that doesn't solve the problem.
You need to add the hidden import for canmatrix
see https://github.com/danielhrisca/asammdf/blob/180a1588737ae7aaf367aaa8fd1c81aff616df16/asammdf.spec#L37

How to fix "missing configuration file: ['config.py']" when importing cv2 on replit

I am trying to use python's opencv (or cv2) module for a project on replit. When I import the class cv2
from cv2 import cv2
I get the following error (on my replit console)
Traceback (most recent call last):
File "main.py", line 1, in <module>
from cv2 import cv2
File "/home/runner/picture-filters/venv/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/home/runner/picture-filters/venv/lib/python3.8/site-packages/cv2/__init__.py", line 111, in bootstrap
load_first_config(['config.py'], True)
File "/home/runner/picture-filters/venv/lib/python3.8/site-packages/cv2/__init__.py", line 109, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
Can someone explain to me how I can fix this error?
I have looked online for solutions, but all I can find are windows specific and linux specific solutions that DO NOT work for replit.

Python dev_appserver cant import `.so` file (Pillow)

Inside my GAE application I try this:
from PIL import Image
And get this:
Traceback (most recent call last):
...
File "/home/sheena/Workspace/Waxed/code/waxed_backend/src/waxed_backend/concerns/misc/views.py", line 57, in home
from PIL import Image
File "libs/PIL/Image.py", line 56, in <module>
from . import _imaging as core
File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 1024, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named PIL._imaging
/path/to/libs/PIL/imaging.so exists. And I have no problem importing anything else from that libs file from within dev_appserver.
And this works fine:
cd /path/to/libs/
python
>>> from PIL import Image
I can only conclude that either dev_appserver somehow breaks impotrt functionality so that .so files aren't recognised.
Has anyone else seen this before? Any idea how to fix it?
_imaging is a PIL dependency written in C. Because it's C and not Python, including the library in your lib folder won't work. You need to define that library in your app.yaml file:
libraries:
- name: PIL
version: latest

Converting .py to .exe getting error no module named userlist

I had created a .py file using below
from appd.request import AppDynamicsClient
import requests
import datetime as db
import time
import matplotlib.pyplot as plt
import pylab
import json
i had used py2exe for converting it into .exe , i had created a setup.py file in which included all the required packages command used
python setup.py py2exe --include package name
it is running fine and creating two folder named dist and build, In dist exe file is present when running the file it is giving the following error
Traceback (most recent call last):
File "appd\__init__.pyc", line 10, in <module>
File "appd\model\__init__.pyc", line 8, in <module>
File "six.pyc", line 92, in __get__
File "six.pyc", line 160, in _resolve
File "six.pyc", line 82, in _import_module
ImportError: No module named UserList
I am not using any module as userlist
I had imported UserList in the file and it was working fine
Actually, problem is that User list package is inside the six package so it is dynamically loaded on the time generation of .exe so it was not able to load the package that's why it was throwing the error.

Unable to import PIL.Image for qrcode

I run into this weird error, I need to use qrcode with pillow, so I did pip install pillow qrcode (after initiating the virtual environment). Then, the following thing happens
>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/vagrant/env/local/lib/python2.7/site-packages/PIL/Image.pyc'>
>>> import qrcode;
>>> qrcode.make("1").show()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/main.py", line 8, in make
return qr.make_image()
File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/main.py", line 186, in make_image
from qrcode.image.pil import PilImage
File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/image/pil.py", line 5, in <module>
import Image
ImportError: No module named Image
from PIL import Image works but qrcode doesn't work. Not sure what is going on
install PIL on Ubuntu:
https://askubuntu.com/questions/156484/how-do-i-install-python-imaging-library-pil
header for your program, code:
##some magic for 3rd party packages
import site
site.main()
##headers
from PIL import Image
##programm
#here your program!!!
--
Your friend!!!

Categories