I just installed the 1.15 Python Image Library in the following folder:
C:\Python26\Lib\site-packages\
However, when I write
from PIL import Image, ImageOps, ImageDraw
I get a error saying unresolved import. Thanks for the help in advance!
The actual modules are just Image, ImageOps, ImageDraw; the PIL package is something one particular distro decided to tack on because they thought those module names were too generic, but they're not actually found in PIL.
Related
I am trying to use OpenCV for Python 3 for the first time. To install, I simply typed "pip3 install opencv-python" into the terminal. When I do this, I see in Finder (I'm on a Mac), that in /usr/local/lib/python3.7/site-packages, I now have a new folder called "cv2". This is strange. Why isn't it cv3, as I used pip3? I do not know.
When I try to import cv2 from python3, it says "No module named 'cv2'". Luckily StackOverflow already has a solution: if I first change directories like: "cd /usr/local/lib/python3.7/site-packages" then I will be able to open cv2. I do not know why this step is necessary for OpenCV. I don't have to do this to "import numpy" for example; "numpy" does not care what directory I start from, and it is listed like just another module like cv2.
Anyways, I change directory to site-packages, start python3, and I import cv2. Now there is a new error. This time cv2 is found, but it says:
"from .cv2 import *
ModuleNotFoundError: No module named 'cv2.cv2'"
For the record, I also have Python 2.7. If I try "cd /usr/local/lib/python2.7/site-packages" and then start Python 2.7, I can import cv2. This is ok, but I want to use OpenCV with Python3.
Let me summarize.
(1) How can I get cv2 or cv3 to import when I start from any directory? Is this ever possible?
(2) How can I get cv3 for python3? cv2 seems to be problematic in python3 because because there is no "cv2.cv2"
The only thing we need to know here is, that 2 in cv2 is not a version. cv2 uses API of C++ while cv uses C API. Version of it is constantly updating being inside CV2.
There is no cv3 there's only import cv2 that opencv older or latest that is updated for old python or latest.
I use windows and Eclipse as IDE. I have installed opencv-python and numpy with pip.
When I try to do:
import cv2
It seems that it is recognised, but I'm not able to use not even a method of this library.
In "C:\Python27\Lib\site-packages" I have both:
opencv_python-3.2.0.7.dist-info
cv2
as folders.
In cv2 i have:
__init__
__init__
cv2.pyd
opencv_ffmpeg320_64.dll
I don't understand what's wrong, the import works but then methods are not recognised.
For example:
import cv2
image = cv2.imread('tmp.png')
cv2.imwrite("tmp.jpg", image)
"imread" and "imwrite" are said to be "undefined variable from import cv2".
Any suggest?
Thank you in advance,
Antonio
Before you ask, I did try putting an image in it, and it didn't work like look at this.
import Image
Image = Image.open('clerky.jpeg')
Image.show()
and this code above comes up with this error below.
import Image
ImportError: No module named 'Image'
If you're using Pillow, the correct usage is
from PIL import Image
To install Pillow on Windows, start the Command Prompt application (or hit WinR and type cmd, then hit Enter). Type
pip install Pillow
hit Enter, and everything should install automatically.
I think you mean from PIL import Image
from PIL import Image
PIL (Python Image Library) has to be installed on your system, AKA "pil" and "Pillow" from time to time. effbot.org/imagingbook/pil-index.htm
When I install PIL http://www.pythonware.com/products/pil/ on 32 bit python, I can use import Image and then use the Image library inside PIL. However, for the 64 bit python, I downloaded http://www.lfd.uci.edu/~gohlke/pythonlibs/. However, when I use import Image, it gives me error, "No Module named Image". However, I can use from PIL import Image.
Why is that I can use import Image directly in one instance and not in another?
You want to install Pillow instead.
It comes in both 32 and 64 bit variants for Windows, and has fixed long-standing issues with the original PIL library.
The PIL library has long been broken when it comes to packaging. Pillow was started as a fork to fix these issues once and for all, and version 2.0.0 added Python 3 support (with a grant from the Python Software Foundation).
They're different libraries. Or, to be specific, they're different packaging of the same library.
PIL is notorious for these sort of issues. Just use Pillow instead.
I'm trying to write some programs using opencv and python. I installed opencv and the python libraries from the repositories. I'm using ubuntu 12.04. The folder /var/lib/python-support/python2.7 contains just 5 files :
cv2.so
cv.py
cv.pyc
simplegeneric-0.7.egg-info
simplegeneric.py
simplegeneric.pyc
From what reading I have done, I think there's supposed to be an opencv folder around here. I'm able to import cv library using
import cv
but
from opencv import cv
And I cannot load the highgui module. Any way to work around this? I would really really like to do something in opencv
You must have installed OpenCV >= 2.3.1. In OpenCV 2.3.1 and higher, Python bindings do not have highgui.
import cv2
import cv2.cv as cv
and you're good to go.
import cv2
img = cv2.imread("image name")
cv2.imshow("window name", img)
cv2.waitKey(0)
You can find more help on OpenCV docs and you could also look at some of the opwncv stuff that I have been doing here.
I hope this helps.
You will get the highgui file in OpenCV folder(installed folder) in include/opencv/highgui.h.