Using Python Imaging Library (PIL) in Eclipse - python

I am attempting to use PIL in Eclipse. I have managed to install the following packages so that this code runs without error:
from PIL import Image
import os
from pylab import *
from scipy.misc import *
im = array(Image.open('empire.jpg').convert('L'))
However, the following:
imshow(im)
Produces the error:
raise RuntimeError('Could not execute image viewer.')
RuntimeError: Could not execute image viewer.
I tried to install the basic Image Viewer from the Eclipse Marketplace. It doesn't solve the problem.
Does anybody know how to get Eclipse display the image?
Thanks in advance.

This ran OK for me (Windows, Python2.6), with the following two changes:
commented out the unused scipy import
added show() at the end

pl.show()
works.
If your import like this:
import matplotlib.pyplot as pl

Related

How can I display an image on VS Code and PyCharm?

I want to choose the best IDE for Python programming so I'm testing different softwares but I have problem.
When I try this code blocks on VS Code I don't see any error but the image is not showing
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread('exit-ramp.jpg')
plt.imshow(image)
VS Code
When I try run the same code on PyCharm I see some errors
PyCharm
But when I run the same code on Jupyter Notebook it works. What can I do?
Bro, try that:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread('exit-ramp.jpg')
plt.imshow(image)
plt.show()
i've made a test in my vscode.
Few weeks ago i used a lot pycharm... but i get some library errors with pandas and pycharm its a little bit heavy.
VSCODE its light and i didnt get any library error that i had with pycharm.
I believe this is a backend problem to be changed in matplotlib. If you start your Python shell whether you are in a bash shell or in vscode, you should use a backend that will show the plot. Otherwise the plt.show() call is required.
So, one solution is to change the backend either manually in you Python shell or when starting the Python shell as explained here below.
Note, however, that I always use the qt5 backend but got the same issue as yours: no plot appears. I changed to the Qt5Agg backend and it worked for me (providing PyQt5 is installed).
So, first solution, you can try to set the backend when starting the Python shell:
ipython --pylab Qt5Agg
You should use a GUI backend amongst the possible backend. If you do not known, try to replace Qt5Agg by auto
The second solution consists in changing the backend manually once in the Python shell:
import matplotlib as plt
plt.use('Qt5Agg')
Right click on your code -> Run current file in interactive window.

Python import cv2 recognised but doesn't work

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

I am not able to import an image into python using the import image way

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

pylab cannot find reference for its modules

I have a mac OS X Yosimite and I'm using python 2.7.10 and Pycharm as my IDLE. I have pylab installed properly but I cannot use any of its modules.
When a try:
from pylab import show
(or any module) it says
ImportError: cannot import name show
But when I run just the line import pylab I get no errors!
I tried leaving that way and calling the module anyway.
pylab.imshow(...)
But I got the same error obviously. Do I have to install those modules separately?
PS: I'm almost sure the problem has nothing to do with the interpreter
Try importing from matplotlib.pyplot, rather than from pylab (this is now the recommended way to import matplotlib):
From example:
from matplotlib.pyplot import imshow
imshow()
Or:
import matplotlib.pyplot as plt
plt.imshow()

Having trouble in creating exe file for python script

I used py2exe to make an exe of my Python script but when I run the exe file it gives me matplotlib data file missing error. What can I do for this thing?
Also I tried using pyInstaller but when everything was completed there was a run time error saying that application failed to start side by side configuration pyinstaller.
I am importing these files in my Python script:
import cv2
import numpy as np
from SimpleCV import *
import SimpleCV
import random
import time
Is there some workarounds or a proper solution I need it badly!
There are some workarounds and information for several modules on py2exe website. For matplotlib check this
import matplotlib
...
setup(
...
data_files=matplotlib.get_py2exe_datafiles(),
)

Categories