PyAutoGui screenshot function weird [duplicate] - python

I'm trying to use pyautogui's screenshot functions with Python 3.6.5 on OSX 10.11.
>>> import pyautogui
>>> image = pyautogui.screenshot()
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyscreeze/__init__.py", line 331, in _screenshot_osx
im = Image.open(tmpFilename)
NameError: name 'Image' is not defined
My understanding is that pyscreeze is failing to get the name Image from Pillow for some reason. I tried to update the pyautogui (it was up to date), then reinstall the pyautogui, which carries all its dependencies including pyscreeze and Pillow along with it.
I found this question with the same issue, but the fix that worked there (reinstalling) isn't working for me.

do
pip install Pillow==0.1.13
since Image is module from PIL

pip3 uninstall pyautogui
pip3 uninstall Pillow
then reinstall the modules and restart you editor.

Related

How can I fix 'openCV has no attribute VideoCapture' in python

I currently have opencv-python 4.5.3.56 installed and running in Python 3.8. However, whenever I try to use the library, I get the error:
Traceback (most recent call last):
File "c:/Users/ryck5/Documents/FA2021/ECEG301/camerademo/color_detection.py", line 108, in <module>
dj.open_camera()
cap = opencv.VideoCapture(0)
AttributeError: module 'opencv' has no attribute 'VideoCapture'
I also tried print(opencv.__version__), but that gave me the same error, just with version instead of VideoCapture. I've tried uninstalling and reinstalling opencv countless times, using the opencv-contrib-python library instead, but nothing has worked. Any help would be much appreciated!
opencv library is used as cv2 namespace in python environment. Most probably you have installed python-opencv and using it.
Try:
import cv2 and then use cv2.VideoCapture().
Also, this is why opencv.__version__ is giving you error as there is no opencv object or library here. Try cv2.__version__.

imread from scipy.misc does not work on pycharm. I can't seem to install PIL either

from scipy.misc import imread
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name 'imread'
If I run the first on pycharm, I get the following message. I've came across that I need to install PIL or Pillow to work with imread. However, trying to install PIL on pycharm gives me this warning.
warning I get
+) interpreter that I'm running on pycharm is:
'/Users/jeongseohyeong/anaconda3/envs/DL/bin/python' (python 3.6)
I've also seen posts that are saying pip install pil works. However, it doesn't seem to work for me (or at least it works for my jupyter notebook which is built in '/Users/jeongseohyeong/anaconda3/bin/python'). Any help would be appreciated.
Imread has been depreciated. Either roll back to scipy 1.1 so you can use it or use another module.

Ubuntu 16.04 Python Version Management Issue

I have Python3.5 and Python3.6 installed on Ubuntu 16.04. I have installed pip for 3.6 and am using 3.6 for development. I tried to install a package (wordcloud) in 3.6 and it appeared to install correctly but I get the following error message:
Traceback (most recent call last):
File "/mnt/data/projects/CSC594/HW01/CSC594-DMARKS-HW01-WordCloud.py", line 11, in <module>
import wordcloud as wc
File "/usr/local/lib/python3.6/dist-packages/wordcloud/__init__.py", line 1, in <module>
from .wordcloud import (WordCloud, STOPWORDS, random_color_func,
File "/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py", line 19, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I am not sure what is happening but, python3 is a symbolic link to python3.5 yet when I execute the code, I am calling it in python3.6. Everything looks fine except when it calls the PIL package. PIL is actually installed in 3.6, but not 3.5.
I don't understand why it switches from:
/usr/local/lib/python3.6/dist-packages
to:
/usr/lib/python3/dist-packages
Why does this happen and how do I resolve this situation?
Trusty offers a 3.5 setup, and that won't change. It may be possible to have the two coexist in the way you suggest, but you are finding it challenging. Recommend deleting your python3.6. (Or switching to an ubuntu based on 3.6.)
Install miniconda3, and use that to provide python3.6, PIL, and friends. Very clean. You'll be glad you did.

Python ImportError: cannot import name '_imagingtk' in virtualenv

I wanted to start using pillow, but I ran into some problems:
At first, I thought I could simply pip install pillow, so I activated my virtualenv and did exactly that. When it didn't worked, I realized that I need to install some dependencies for pillow (installation). I'm on Ubuntu 14.04. But even after I installed those dependencies and reinstalled pillow, the Code didn't work. Until I tried it outside of the virtualenv and pip installed pillow on my main Python3.4 installation, where my Code suddenly worked.
import tkinter as tk
from PIL import Image, ImageTk
def show(img, text=""):
root = tk.Tk()
root.title(text)
photo = ImageTk.PhotoImage(img)
image_lbl = tk.Label(root, image=photo)
image_lbl.image = photo
image_lbl.pack()
root.mainloop()
show(Image.open("test.jpg"), text="Test")
Error:
Traceback (most recent call last):
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 176, in paste
tk.call("PyImagingPhoto", self.__photo, block.id)
_tkinter.TclError: invalid command name "PyImagingPhoto"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/Code/Python/main/test.py", line 15, in <module>
show(Image.open("test.jpg"), text="Test")
File "~/Code/Python/main/test.py", line 8, in show
photo = ImageTk.PhotoImage(img)
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 115, in __init__
self.paste(image)
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 180, in paste
from PIL import _imagingtk
ImportError: cannot import name '_imagingtk'
So i had this same problem for the last few days and finally got it resolved. I am running Ubuntu 14.04 as well and i believe i am running python 2.7.
The code that I was running was the following
from Tkinter import *
from PIL import Image, ImageTk
app_root = Tk()
img = ImageTk.PhotoImage(Image.open("detailedmodel.jpg"))
imglabel = Label(app_root, image=img).grid(row=1, column=1)
app_root.mainloop()
This was generating the error:
ImportError: cannot import name _imagingtk
I tried a few different things to solving this error based on other solutions online, generally just uninstalling and installing pillow with different developer libraries but the script kept crashing with the same error.
Finally I found that in the terminal entering:
sudo pip2.7 install -I --no-cache-dir Pillow
seemed to solve the problem. With the other installs I guess I was working with the wrong version of pillow for python 3 not 2.7.
Hope this helps but it looks like you might have solved the problem already.
Delete PIL and Pillow packages in lib-packages in your python directory:
I am using Conda Env, so
conda remove PIL
and
conda remove pillow
or
Delete them directly in lib-packages dir (Suggestion: Make a backup folder).
then, install pillow in this site : http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg.
If you using Windows Platform install PIL this site : http://www.pythonware.com/products/pil/ (choose based your python version).

PIL Module Error

I get the following error running the simple python script below:
Traceback (most recent call last):
File "/home/user/Desktop/python/folder/pil_test.py", line 4, in <module>
im = Image.open('screenshot.png')
AttributeError: 'module' object has no attribute 'open'
I run Debian Wheezy with KDE.
I have installed pillow via pip.
The script ran well on my previous system, so I suspect the issue
lies outside of my source code.
I feel slit up and have no idea where to start to solve that issue.
Just reinstalling pillow did not do the job for me.
What else could I do?
from PIL import Image
im = Image.open('screenshot.png')
left = '10'
top = '10'
right = '10'
bottom = '10'
im = im.crop((left, top, right, bottom)) # defines crop points
im.save('screenshot.png')
It appears uninstalling 'pillow' and install 'pil' did the job for me:
sudo pip uninstall pillow
sudo pip install pil
This is strange in so far as I thought installing pillow via pip must have included PIL automatically.
I do not know why. But it works now!

Categories