I tried to run this simple program on python 2.5 and get the following error, I am not sure what is going on.
Code:
import pylab
pylab.figure(1) # make figure 1 the current figure
pylab.plot([1,2,3,4], [1,7,3,5]) # draw on figure 1
pylab.show() # show figure on screen
Error:
Traceback (most recent call last):
File "/Users/sebastiancarrasco/Desktop/Courses/6.00.2x/Week1/plotting-seg1.py", line 3, in <module>
pylab.figure(1) # make figure 1 the current figure
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pyplot.py", line 270, in figure
**kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 85, in new_figure_manager
figManager = FigureManagerTkAgg(canvas, num, window)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 403, in __init__
self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 670, in __init__
NavigationToolbar2.__init__(self, canvas)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 2273, in __init__
self._init_toolbar()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 719, in _init_toolbar
command=self.home)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 702, in _Button
im = Tk.PhotoImage(master=self, file=file)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3294, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3250, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl-data/images/home.ppm": permission denied
For anyone else who runs into this problem and comes across this page: I eventually found the answer here. Long story short: some problem with the installer messes up the permissions for all the files in the "images" folder. All you have to do is change the permissions to give yourself read privileges.
Related
I created GUI in Python (Python2.7) using Tkinter. I wish to have it up and running for both RHEL7.4 and RHEL5.11 versions. On REHL7.4, it works fine but on RHEL5.11, it gives the following error:
Traceback (most recent call last):
File "configure_workstation.py", line 28, in <module>
app = ConfigureWorkstation(wsObj)
File "/tmp/hnoman/v0.62/ConfigureWorkstation.py", line 90, in __init__
frame = F(self.fMenu, self)
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 35, in __init__
self.generateHostnameFrame()
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 50, in generateHostnameFrame
self.oLocation = ttk.OptionMenu(self.fHostname, self.location, dict[1], *dict.values())
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 1591, in __init__
Menubutton.__init__(self, master, **kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 797, in __init__
Widget.__init__(self, master, "ttk::menubutton", kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 554, in __init__
_load_tile(master)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 46, in _load_tile
master.tk.eval('package require tile') # TclError may be raised here
_tkinter.TclError: can't find package tile
Can someone guide how to overcome this?
This is my code:
from tkinter import *
logoImage = PhotoImage(file='logo.png')
logoLabel = Label(root, image=logoImage, bg='dodgerblue3')
logoLabel.grid(row=0, column=0)
The image is in the same directory as the project. In fact, when I open it with cmd or Python it works. But when I use VS Code or Turn it into .exe file, it shows this error:
Traceback (most recent call last):
File "c:\Users\Simo\OneDrive\Python\Scientific calculator\calc.py", line 180, in <module>
logoImage = PhotoImage(file='logo.png')
File "C:\Users\Simo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Simo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "logo.png": no such file or directory
How can I fix this?
Maybe try putting the file into your workspace and using the relative path.
I've been working with the same Python/Tkinter code for a week now, and seemingly out of nowhere I am getting the error "Bad label specification":
Traceback (most recent call last):
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 1188, in <module>
gui = App()
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 62, in __init__
self.createWidgets()
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 70, in createWidgets
self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor=N)
File "C:\Program Files\Python27\lib\lib-tk\ttk.py", line 776, in __init__
Widget.__init__(self, master, "ttk::labelframe", kw)
File "C:\Program Files\Python27\lib\lib-tk\ttk.py", line 555, in __init__
Tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Program Files\Python27\lib\lib-tk\Tkinter.py", line 2096, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: Bad label anchor specification 443664640LN
It is caused by the line self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor=N)
As this worked a few hours ago, maybe this is an environmental issue? I cannot find anything about this issue on Google.
Changing it to self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor='n') fixes the issue.
According to the source code for LabelFrame, the label anchors are defined as strings 'n', 'we', etc.
I'm using python's Turtle Graphics and I want to set a background picture. However, it's not working. I need an answer quick as I have an assignment for my Computer Science class tomorrow >_<. Here's my code:
import time
import sys
import turtle
##Render
turtle.bgpic("background.png")
##End
turtle.done()
And I'm getting this error:
Traceback (most recent call last):
File "C:/Users/Alfie/Desktop/Youtube Game/Youtube.py", line 6, in <module>
turtle.bgpic("background.png")
File "<string>", line 8, in bgpic
File "C:\Python27\lib\lib-tk\turtle.py", line 1397, in bgpic
self._bgpics[picname] = self._image(picname)
File "C:\Python27\lib\lib-tk\turtle.py", line 503, in _image
return TK.PhotoImage(file=filename)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3366, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3320, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't recognize data in image file "background.png"
Followed with a Not Responding screen. Anyone know what the error is?
Tk only supports GIF, PGM and PPM according to this question. Your turtle library uses Tk internally and so you have to use a GIF file for your background.
I have tried that function.
I have used format .png --> OK
Remember \\ instead of \
ex: turtle.bgpic("""C:\\Users\\ASUS\\Downloads\\test.gif""")
--> So I think at that time, we can use .png in Python turtle.
I'm trying to change the background image in a turtle window.
The code reads simply as this:
import turtle
turtle.bgpic("france53.gif")
The turtle window shows up blank and I get the following error message:
Traceback (most recent call last):
File "<ipython-input-25-45373f8f3ea2>", line 1, in <module>
bgpic("france53.gif")
File "<string>", line 1, in bgpic
File "/Users/danielcharrier/anaconda/lib/python3.4/turtle.py", line 1482, in bgpic
self._setbgpic(self._bgpic, self._bgpics[picname])
File "/Users/danielcharrier/anaconda/lib/python3.4/turtle.py", line 738, in _setbgpic
self.cv.itemconfig(item, image=image)
File "<string>", line 1, in itemconfig
File "/Users/danielcharrier/anaconda/lib/python3.4/tkinter/__init__.py", line 2416, in itemconfigure
return self._configure(('itemconfigure', tagOrId), cnf, kw)
File "/Users/danielcharrier/anaconda/lib/python3.4/tkinter/__init__.py", line 1310, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: image "pyimage12" doesn't exist
The file "france53.gif" is in the working directory. What should I do to make it work?
I'm using the Anaconda distribution for Mac OS X.
Thanks!