How to fix AttributeError with ImageTk and Tkinter in python3.6? - python

Traceback (most recent call last):
File "C:/Users/Murad/PycharmProjects/OmrTest/images/GUI.py", line 765, in <module>
obj = Login(master)
File "C:/Users/Murad/PycharmProjects/OmrTest/images/GUI.py", line 35, in __init__
self.bg = ImageTk.PhotoImage(file="unnamed.png")
File "C:\Users\Murad\PycharmProjects\OmrTest\venv\lib\site-packages\PIL\ImageTk.py", line 89, in __init__
image = _get_image_from_kw(kw)
File "C:\Users\Murad\PycharmProjects\OmrTest\venv\lib\site-packages\PIL\ImageTk.py", line 58, in _get_image_from_kw
return Image.open(source)
File "C:\Users\Murad\PycharmProjects\OmrTest\venv\lib\site-packages\PIL\Image.py", line 2904, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'unnamed.png'
Exception ignored in: <bound method PhotoImage.__del__ of <PIL.ImageTk.PhotoImage object at 0x000002A705690748>>
Traceback (most recent call last):
File "C:\Users\Murad\PycharmProjects\OmrTest\venv\lib\site-packages\PIL\ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
So I was doing a project in pycharm. how do I Solve this problem?

line 35, init self.bg = ImageTk.PhotoImage(file="unnamed.png")
Where is the file unnanmed.png located?
Use :
self.bg= ImageTk.PhotoImage(Image.open(file_path))
file_path should be full or relative path of the file if it is not in the root directory.

Related

python > Selenium > Traceback

I tried a lot to fix Traceback Error
The same code is working in Pycharm , But when I put it in replit.com , is shows this Error
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/xauth.py", line 43, in __init__
raw = open(filename, 'rb').read()
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.Xauthority'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 9, in <module>
import pyautogui
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/protocol/display.py", line 60, in __init__
auth_name, auth_data = connect.get_auth(self.socket,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/support/connect.py", line 91, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/support/unix_connect.py", line 103, in new_get_auth
au = xauth.Xauthority()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/xauth.py", line 45, in __init__
raise error.XauthError('~/.Xauthority: %s' % err)
Xlib.error.XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/runner/.Xauthority'
please help me
Try this:
sudo apt-get install xauth
If it doesn't work there are other answers to the problem in here

AttributeError: 'AudioFileClip' object has no attribute 'reader'

when i tried to run this code, i got the "AttributeError" but idk why? please help me.
import os
import random
from moviepy.editor import *
List_image = os.listdir("müzik\kapaklar")
kapak_num = random.sample(range(1,len(List_image)+1),len(List_image))
List_songs = os.listdir("müzik\hazırlanacaklar")
for x in range(len(List_songs)):
songs = List_songs[x+1]
kapak = List_image[kapak_num[x+1]]
audio = AudioFileClip(songs) ### problem is here ###
image = ImageClip(kapak).set_duration(audio.duration)
video = image.set_audio(audio)
outfile = f"müzik\yapılanlar\%n_with_image.mp4",songs
video.write_videofile(outfile, fps=1)
error message:
C:\Users\erkan\Desktop\ChatCop\venv\Scripts\python.exe "C:/Users/erkan/Desktop/ChatCop/deus ex machina.py"
Traceback (most recent call last):
File "C:/Users/erkan/Desktop/ChatCop/deus ex machina.py", line 15, in <module>
audio = AudioFileClip(songs) # sıkıntı burada
File "C:\Users\erkan\Desktop\ChatCop\venv\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 72, in __init__
buffersize=buffersize)
File "C:\Users\erkan\Desktop\ChatCop\venv\lib\site-packages\moviepy\audio\io\readers.py", line 50, in __init__
infos = ffmpeg_parse_infos(filename)
File "C:\Users\erkan\Desktop\ChatCop\venv\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 276, in ffmpeg_parse_infos
"path.")%filename)
OSError: MoviePy error: the file 70s Japanese Jazz Mix (Rare Groove, Jazz-Funk, Hard Bop, Modal, Fusion, Breaks).mp3 could not be found!
Please check that you entered the correct path.
Exception ignored in: <bound method AudioFileClip.__del__ of <moviepy.audio.io.AudioFileClip.AudioFileClip object at 0x0000026210D45710>>
Traceback (most recent call last):
File "C:\Users\erkan\Desktop\ChatCop\venv\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 94, in __del__
self.close()
File "C:\Users\erkan\Desktop\ChatCop\venv\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 89, in close
if self.reader:
AttributeError: 'AudioFileClip' object has no attribute 'reader'
Process finished with exit code 1

How to delete ADUser using Python pyad module

I'm having a problem with deleting ADUser.
pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
user = aduser.ADUser.from_dn("cn=myuser, ou=staff, dc=domain, dc=com")
user.delete()
Unfortunately I could not figure out how to format this text to look like a real traceback
Traceback (most recent call last):
File "C:/Automation/qa/robot2/python_lib/keywords/AD/unittest.py", line 34,
in <module>
ad_connect.bg_ad_user_remove(user_login='vasya.oconnor#test-acme.com',dn_string= dn_string)
File "C:\Automation\qa\robot2\python_lib\keywords\AD\_bg_ad_general.py", line 156, in bg_ad_user_remove
user.delete()
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 537, in delete
if not parent:
File "C:\Python27\lib\site-packages\future\types\newobject.py", line 90, in __nonzero__
return type(self).__len__(self)
AttributeError: type object 'ADContainer' has no attribute '__len__'

fetch_lfw_people error on changing parameters (Python)

I'm following this example on the sklean doc sklearn_doc ,I can execute the example but if I change from:
fetch_lfw_people(min_faces_per_person=70, resize=0.4)
to
fetch_lfw_people(min_faces_per_person=200, resize=1.0)
I'haven't changed anything but this parameters ,is an int for another int and a float for another float,I can't see the problem
I get the following error:
Traceback (most recent call last):
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/datasets/lfw.py", line 144, in _load_imgs
from scipy.misc import imread
ImportError: cannot import name 'imread'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.6/site-packages/scipy/misc/pilutil.py", line 19, in <module>
from PIL import Image, ImageFilter
ModuleNotFoundError: No module named 'PIL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/datasets/lfw.py", line 146, in _load_imgs
from scipy.misc.pilutil import imread
File "/home/user/.local/lib/python3.6/site-packages/scipy/misc/pilutil.py", line 21, in <module>
import Image
ModuleNotFoundError: No module named 'Image'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/PycharmProjects/practica/ejercicio1.py", line 25, in <module>
lfw_people = fetch_lfw_people(min_faces_per_person=200, resize=1.0)
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/datasets/lfw.py", line 335, in fetch_lfw_people
min_faces_per_person=min_faces_per_person, color=color, slice_=slice_)
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/externals/joblib/memory.py", line 562, in __call__
return self._cached_call(args, kwargs)[0]
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/externals/joblib/memory.py", line 510, in _cached_call
out, metadata = self.call(*args, **kwargs)
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/externals/joblib/memory.py", line 744, in call
output = self.func(*args, **kwargs)
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/datasets/lfw.py", line 236, in _fetch_lfw_people
faces = _load_imgs(file_paths, slice_, color, resize)
File "/home/user/anaconda3/envs/tema4/lib/python3.6/site-packages/sklearn/datasets/lfw.py", line 149, in _load_imgs
raise ImportError("The Python Imaging Library (PIL)"
ImportError: The Python Imaging Library (PIL) is required to load data from jpeg files

AttributeError when running rqt commands

I am trying to use rqt in ROS hydro but I see the following errors:
Traceback (most recent call last): File
"/opt/ros/hydro/bin/rqt_graph", line 8, in
sys.exit(main.main(sys.argv, standalone='rqt_graph.ros_graph.RosGraph')) File
"/opt/ros/hydro/lib/python2.7/dist-packages/rqt_gui/main.py", line 59,
in main
return super(Main, self).main(argv, standalone=standalone, plugin_argument_provider=plugin_argument_provider,
plugin_manager_settings_prefix=str(hash(os.environ['ROS_PACKAGE_PATH'])))
File "/opt/ros/hydro/lib/python2.7/dist-packages/qt_gui/main.py", line
336, in main
from python_qt_binding import QT_BINDING File "/opt/ros/hydro/lib/python2.7/dist-packages/python_qt_binding/init.py",
line 55, in
from .binding_helper import loadUi, QT_BINDING, QT_BINDING_MODULES, QT_BINDING_VERSION # #UnusedImport File
"/opt/ros/hydro/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py",
line 265, in
getattr(sys, 'SELECT_QT_BINDING_ORDER', None), File "/opt/ros/hydro/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py",
line 84, in _select_qt_binding
QT_BINDING_VERSION = binding_loader(required_modules, optional_modules) File
"/opt/ros/hydro/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py",
line 139, in _load_pyqt
_named_import('PyQt4.%s' % module_name) File "/opt/ros/hydro/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py",
line 106, in _named_import
module = builtins.import(name) AttributeError: 'module' object has no attribute 'import'

Categories

Resources