Greetings
I am running the following code on python3 using Windows 11 WSL2
import sys
import json
import os
#os.system("pip install opencv-python")
#os.system("pip install numpy")
#os.system("pip install urllib3")
os.system("pip install PIL")
os.system("pip install pillow")
os.system("pip install urllib3")
os.system("pip install chardet")
import cv2
import numpy as np
import urllib.request
from PIL import Image
url1 = "https://pbs.twimg.com/profile_images/987617293306859520/T4aHjh5r_400x400.jpg"
url2 = "http://3.bp.blogspot.com/-JVIkYYRHoW0/Vp-aV0ALdUI/AAAAAAAADhc/huHp_gFx_b4/s1600/IMG_6572.JPG"
def convert_to_grayscale(pic1,pic2):
gray_img1 = np.array(Image.open(pic1))
gray_img2 = np.array(Image.open(pic2))
gray1 = cv2.cvtColor(gray_img1,cv2.COLOR_RGB2GRAY)
gray2 = cv2.cvtColor(gray_img2,cv2.COLOR_RGB2GRAY)
return (gray_img1,gray_img2)
def url_to_image(url):
data = urllib.request.urlopen(url)
contents = data.read()
return contents
if __name__ == '__main__':
image1 = url_to_image(url1)
image2 = url_to_image(url2)
gray_pic1, gray_pic2 = convert_to_grayscale(image1,image2)
cv2.imshow('Gray scaled image 1',gray_pic1)
cv2.imshow('Gray scaled image 2',gray_pic2)
cv2.waitKey()
cv2.destroyAllWindows()
When I run this piece of code I get the following error:
This was my first error log:
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
File "bruteForceOpenCV.py", line 34, in <module>
gray_pic1, gray_pic2 = convert_to_grayscale(image1,image2)
File "bruteForceOpenCV.py", line 20, in convert_to_grayscale
gray_img1 = np.array(Image.open(pic1))
File "/home/tmm88/.local/lib/python3.8/site-packages/PIL/Image.py", line 2953, in open
fp = builtins.open(filename, "rb")
ValueError: embedded null byte
now, i am getting the following:
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pillow in /home/tmm88/.local/lib/python3.8/site-packages (9.0.1)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in /home/tmm88/.local/lib/python3.8/site-packages (1.26.8)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: chardet in /usr/lib/python3/dist-packages (3.0.4)
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
File "bruteForceOpenCV.py", line 37, in <module>
gray_pic1, gray_pic2 = convert_to_grayscale(image1,image2)
File "bruteForceOpenCV.py", line 23, in convert_to_grayscale
gray_img1 = np.array(Image.open(pic1))
File "/home/tmm88/.local/lib/python3.8/site-packages/PIL/Image.py", line 2953, in open
fp = builtins.open(filename, "rb")
ValueError: embedded null byte
I am currently being able to:
- make an http request for the images
I am not being able to:
- convert the images to greyscale
- bruteforce them and compare them with opencv
any help is appreciated
can someone please help me to fix this?
thank you so much
T.
CodePudding user response:
"No matching distribution found for PIL"
Did you install pillow?
$ pip install pillow
$ pip install urllib3
$ pip install chardet
After you did it, close terminal and try again.
If you don't know what packages you have installed, you must run:
$ pip list
or if you want it in a txt file...
$ pip list > mypackages.txt
Hope I helped you.
CodePudding user response:
pip list is currently returning the following:
Package Version
---------------------- --------------------
async-generator 1.10
attrs 19.3.0
Automat 0.8.0
beautifulsoup4 4.10.0
blinker 1.4
bs4 0.0.1
certifi 2019.11.28
chardet 3.0.4
Click 7.0
cloud-init 21.4
colorama 0.4.3
command-not-found 0.3
configobj 5.0.6
constantly 15.1.0
cryptography 2.8
dbus-python 1.2.16
distlib 0.3.4
distro 1.4.0
distro-info 0.23ubuntu1
entrypoints 0.3
filelock 3.4.2
h11 0.13.0
httplib2 0.14.0
hyperlink 19.0.0
idna 2.8
importlib-metadata 1.5.0
incremental 16.10.1
Jinja2 2.10.1
jsonpatch 1.22
jsonpointer 2.0
jsonschema 3.2.0
keyring 18.0.1
language-selector 0.1
launchpadlib 1.10.13
lazr.restfulclient 0.14.2
lazr.uri 1.0.3
MarkupSafe 1.1.0
more-itertools 4.2.0
MouseInfo 0.1.3
netifaces 0.10.4
numpy 1.22.2
oauthlib 3.1.0
opencv-python 4.5.5.62
outcome 1.1.0
pexpect 4.6.0
Pillow 9.0.1
pip 22.0.3
pipenv 2022.1.8
platformdirs 2.5.0
pyasn1 0.4.2
pyasn1-modules 0.2.1
PyAutoGUI 0.9.53
PyGetWindow 0.0.9
PyGObject 3.36.0
PyHamcrest 1.9.0
PyJWT 1.7.1
pymacaroons 0.13.0
PyMsgBox 1.0.9
PyNaCl 1.3.0
pyOpenSSL 19.0.0
pyperclip 1.8.2
PyRect 0.1.4
pyrsistent 0.15.5
PyScreeze 0.1.28
pyserial 3.4
python-apt 2.0.0 ubuntu0.20.4.6
python-debian 0.1.36ubuntu1
python3-xlib 0.15
pytweening 1.0.4
pyxattr 0.6.1
PyYAML 5.3.1
requests 2.22.0
requests-unixsocket 0.2.0
SecretStorage 2.3.1
selenium 4.1.0
service-identity 18.1.0
setuptools 45.2.0
simplejson 3.16.0
six 1.14.0
sniffio 1.2.0
sortedcontainers 2.4.0
sos 4.2
soupsieve 2.3.1
ssh-import-id 5.10
systemd-python 234
trio 0.19.0
trio-websocket 0.9.2
Twisted 18.9.0
ubuntu-advantage-tools 27.6
ufw 0.36
unattended-upgrades 0.1
urllib3 1.26.8
virtualenv 20.13.1
virtualenv-clone 0.5.7
wadllib 1.3.3
wheel 0.34.2
wsproto 1.0.0
youtube-dl 2020.3.24
zipp 1.0.0
zope.interface 4.7.1
I still get this error while running the script:
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pillow in /home/tmm88/.local/lib/python3.8/site-packages (9.0.1)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in /home/tmm88/.local/lib/python3.8/site-packages (1.26.8)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: chardet in /usr/lib/python3/dist-packages (3.0.4)
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
File "bruteForceOpenCV.py", line 37, in <module>
gray_pic1, gray_pic2 = convert_to_grayscale(image1,image2)
File "bruteForceOpenCV.py", line 23, in convert_to_grayscale
gray_img1 = np.array(Image.open(pic1))
File "/home/tmm88/.local/lib/python3.8/site-packages/PIL/Image.py", line 2953, in open
fp = builtins.open(filename, "rb")
ValueError: embedded null byte