I want to do some image processing and I encountered a problem. Importing the pillow module doesn't seem to work. I found a simple script here to check what packages are installed and I found it, but importing it doesn't seem to work.
Here's the code I'm trying to run:
import pip
installed_packages = pip.get_installed_distributions()
installed_pillow_packages = [
"%s==%s" % (i.key, i.version)
for i in installed_packages
if "pil" in i.key.lower()
]
print(installed_pillow_packages)
import pillow
And here's the result:
runfile('C:/Users/Augustas/.spyder2/temp.py', wdir=r'C:/Users/Augustas/.spyder2')
['pillow==2.6.1']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 601, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 66, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Augustas/.spyder2/temp.py", line 7, in <module>
import pillow
ImportError: No module named pillow
I'm running this on Windows 8.1 using Spyder and Python 2.7.9.
You are importing incorrectly. Try using:
import PIL
or
from PIL import Image
PIL, i.e., Python Imaging Library is no longer maintained, Pillow is used instead. To maintain backwards compatibility, the PIL module name is used in imports.
In fact, Pillow is installed under name "PIL", so:
import PIL as pillow
from PIL import Image
...
Look this:
Checkout the doc:
http://pillow.readthedocs.org/handbook/tutorial.html
You must import it like that:
import PIL
Related
This question already has answers here:
ImportError: No module named PIL
(30 answers)
Closed 10 months ago.
I've imported the pyscreenshot module, but when I run code with it, it gives me this error:
Traceback (most recent call last):
File "myfilepaththatiwontshow", line 7, in <module>
import pyscreenshot
File "C:\Users\A\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreenshot\__init__.py", line 4, in <module>
from pyscreenshot.childproc import childprocess_backend_version
File "C:\Users\A\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreenshot\childproc.py", line 6, in <module>
from pyscreenshot.imcodec import codec
File "C:\Users\A\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreenshot\imcodec.py", line 3, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I've checked twice and the pyscreenshot module is installed and tried running
pip install PIL
but apparently it doesn't exist.
According to its docs, Pillow:
Pillow is the friendly PIL fork by Alex Clark and Contributors
This library is a drop-in replacement for PIL, which is no longer available or supported. To install pillow, use:
pip uninstall PIL
pip install pillow
I am doing a project for traffic signal automation on a virtual machine. It needs to detect cars using image detection process.
Code:
import cv2
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox
im = cv2.imread('cars_4.jpeg')
bbox, label, conf = cv.detect_common_objects(im)
output_image = draw_bbox(im, bbox, label, conf)
plt.imshow(output_image)
plt.show()
print('Number of cars in the image is '+ str(label.count('car')))
Operating system: Debian Buster with Raspberry Pi Desktop
https://www.raspberrypi.org/software/raspberry-pi-desktop/
Kernel version : 4.19
Python Version: 3.7.3
Pip Version:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 21.1.1 from /home/pi/.local/lib/python3.7/site-packages/pip (python 3.7)
Libraries used:
-Open cv
cvlib
matplotlib.
After installing cvlib it requires me to install tensor flow, after installation of tensorflow at the time of execution this error occurs:
Error :
(venv) pi#raspberry:~/Desktop/TSA $ python3 main.py
Traceback (most recent call last):
File "main.py", line 3, in <module>
import cvlib as cv
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/cvlib/_init_.py", line 8, in <module>
from .gender_detection import detect_gender
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/cvlib/gender_detection.py", line 3, in <module>
from tensorflow.keras.utils import get_file
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/tensorflow/_init_.py", line 23, in <module>
from tensorflow.python import *
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/tensorflow/python/_init_.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/usr/lib/python3.7/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.7/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /home/pi/Desktop/TSA/venv/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: cannot open shared object file: No such file or directory
Tried adding
"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64/"
in .bashrc file, still same error.
Based on error it seems like something is wrong with your installation of cvlib.
I guess you can try again:
pip install opencv-python tensorflow
pip install cvlib
And see if that yields some error message that might direct to you what could be wrong.
As mentioned in the comment by #swarles-barkley maybe your environment requires the above to actually be:
python3 -m pip install opencv-python tensorflow
python3 -m pip install cvlib
EDIT (after a comment):
Again something is definitely odd with your env setup. You can try to uninstall and then reinstall tensorflow and cvlib and while doing so closely look for any warnings coming out from compile process.
This discussion might give you some ideas on how to debug the issue.
I installed OpenCV using command
pip install OpenCV-python
in python 3.6.0
but shows error when I used in code
code
import cv2
def vidPlay():
cap = cv2.VideoCapture(0)
ret, inputImage = cap.read()
if ret==True:
return inputImage
cap.release()
a = vidPlay()
print(a)
print("done ")
cv2.imshow(a)
Error
File "<stdin>", line 1, in <module>
File "C:\Users\yyy\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\yyy\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/yyy/Desktop/cameraPlay.py", line 1, in <module>
import cv2
File "C:\Users\yyy\Anaconda3\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: The specified module could not be found.
i tried different solutions on questions but not solve my issue.
This question seems to be a duplicate of the following question:
DLL Load Failed Error when importing CV2
I'm copying the accepted answer from that question, for the ease:
You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit
version) I think it would be easier.
Written by: #thewaywewere
I'm trying to create a function which reads pptx files. The only module I found is python-pptx. But unfortunately, it raises errors.
There were some problems with installing Pillow when I did: pip install python-pptx so I installed it easy_install Pillow which seems to be working. Then I installed python-pptx. The problem is that when I execute the function it still raises error:
Traceback (most recent call last):
File "C:/Users/Milano/Desktop/Projekty/FS Dropbox/Dropbox/word_counter.py", line 38, in <module>
print get_pptx_word_count('pptx.pptx')
File "C:/Users/Milano/Desktop/Projekty/FS Dropbox/Dropbox/word_counter.py", line 15, in get_pptx_word_count
from pptx import Presentation
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\__init__.py", line 15, in <module>
from pptx.api import Presentation # noqa
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\api.py", line 17, in <module>
from .package import Package
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\package.py", line 16, in <module>
from .parts.image import Image, ImagePart
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\parts\image.py", line 13, in <module>
import Image as PIL_Image
ImportError: No module named Image
What should I do? I'm on virtualenv. Tried to uninstall Pillow and install PIL but it didn't find anything.
pillow moves all the PIL modules to the PIL package. You will need to modify the import to PIL.Image.
I just installed python xy 2.7.9 on Windows 7. I went to run some previously written code in Spyder which calls:
from scipy.sparse import linalg as sla
However, I get the following error:
File "C:\Python27\lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in <module>
from .matfuncs import *
File "C:\Python27\lib\site-packages\scipy\sparse\linalg\matfuncs.py", line 20, in <module>
import scipy.misc
File "C:\Python27\lib\site-packages\scipy\misc\__init__.py", line 44, in <module>
from . import doccer
ImportError: cannot import name doccer
Does anyone know how to fix this? I find this weird because it worked with my previous copy of Python (which I uninstalled before installing the new version).
Thanks!
What worked for me is moving doccer.py from "misc" folder to "_lib" folder (which are in path /usr/lib/python3/dist-packages/scipy/ for me).
I found this in a release note of scipy : https://github.com/scipy/scipy/pull/9652