I am having an issue with LCDproc, using the python package here http://pydoc.net/Python/lcdproc/0.03/lcdproc.server/
Quick background - I am parsing airplay metadata from a pipe and displaying it on an lcd screen as a part of a Raspberry Pi music player project.
I'd like to display a screen when the user changes the playback volume. I thought the way to do this was to add a new screen and set a timeout. This works the first time, and subsequently causes an error:
Traceback (most recent call last):
File "./lcdtunes.py", line 194, in <module>
main()
File "./lcdtunes.py", line 147, in main
vol_screen.set_heartbeat("off")
AttributeError: 'NoneType' object has no attribute 'set_heartbeat'
The script is available here: https://github.com/john-a-harris/lcdtunes/blob/master/lcdtunes.py
I am no coder, as will be obvious, but I think that the error means that the screen I think I am adding in line 146 doesn't actually exist.
My question is why - what am I doing wrong here?
Is there another way to achieve this or am I missing something blindingly obvious?
Please be gentle with me - this is my first question!
Related
I'm trying to get the ODB library working. In the documentation at https://python-obd.readthedocs.io/en/latest/ it lists the following code:
import obd
connection = obd.OBD("/dev/ttyUSB0") # connects to USB or RF port
cmd = obd.commands.SPEED # select an OBD command (sensor)
response = connection.query(cmd) # send the command, and parse the response
print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to("mph")) # user-friendly unit conversions
When I put this in a file called test.py and I run it:
python2 test.py
I get the following error message:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import obd
File "/home/ubuntu/obd.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'OBD'
Stackoverflow comes up with several iterations of this error message, but none clearly explain the problem, only giving specific solutions to those libraries.
I guess it's obvious that I'm new to Python, and I'm having trouble interpreting this error message, even after several hours of writing several small Python programs. I am of course also interested in why the error message is so un-intuitive to a newcomer and where I can gain the common knowledge I might be missing, and I guess this is as good a case to discover that through as any.
So far I have figured out the following:
<module> refers to the name of my python script that I am trying to run.
The mistake I made at first, was to name my test.py file, initially obd.py. This conflicted with the import obd as it was trying to import the file itself - even after I deleted it! The reason was that when I tried to run it the first time, it created a file called obd.pyc - and even though obd.py was no longer there, import OBD found the initially created obd.pyc and tried to import that - which of course does not contain the OBD object from the library I was trying to use.
This is not the detailed answer I'm looking for, so please add a more detailed explanation - or a link to how Python compiling works, if you can.
So i have a problem, whenever i try to use Pyinstaller with Pygame, it won't work, instead after a second, it says that it stopped working. I ran a test program before (consisting of a block moving up and down and a block following your cursor) and it worked just fine. However, i tried implementing some text using pygame.font.Font function and suddenly it stopped working. I tried using a try function to see if it could catch it, and nothing. I tried using no font, nothing. This also works as a regular .py file as well, just not as an executable. I'll include further info as needed if need be.
Thanks in advance!
EDIT:i was able to produce an error thanks to kaktus_car letting me know that there was an update to pygame, here it is:
Traceback (Most recent call last):
"test.py", line 20, in <module>
File "site-packages\pygame\pkgdata.py", line 50, in getResource
File "site-packages\pkg_resources\__init__.py", line 1134, in resource_exists
File "site-packages\pkg_resources\__init__.py", line 1404, in has_resource
File "site-packages\pkg_resources\__init__.py", line 1472, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
[1276] Failed to execute script test
So, i managed to figure it out! What i did was i instaed used a different application than pyinstaller. Instead, i used cx_Freeze. If you are having this kind of problem as well, the link is Here the directions are rather clear and you have the option to include files, so if you have a game with made graphics, it can include them.
I am having a weird situation where the trace for an AttributeError keeps referencing the exact same absolute line number in my code.
Traceback (most recent call last):
File "<ipython-input-59-513669e63f3e>", line 4, in <module>
"line of code being run"
File "modulepath", line 148, in "method that contains the line of code"
"content of the line causing the error"
AttributeError: 'list' object has no attribute 'attribute_name'
If I make line 148 empty (by putting in new lines, etc.) or if I put a comment on line 148, the trace keeps pointing to line 148 as the source of the error.
I am having trouble debugging this particular error in general since I am (to the best of my knowledge) not using that particular attribute on any list object in my code (but it seems to indicate that I'm doing so). I will figure out that issue on my own. My main question is: what causes Spyder to repeatedly reference the exact same absolute line number in a traceback? Thank you.
When in doubt, use a fresh new console - that worked for me.
I have a program that runs in Python, without the console present (which is to say, I've compiled it using py2exe). I want people to be able to quit from the main menu, or by a particular key-press in-game (say, Shift+Q). I'm running it, for now, in Windows, though I am working on compiling Linux/Mac versions. Pressing the X button works if there's no 'while' loop running, it seems, and that closes it correctly, otherwise it seems to 'store' the close command wait until the current loop is closed.
As for menu options, I've looked thoroughly through documentation and Stackoverflow and tried quit(), exit(), sys.exit() and every combination I can find, but every time I get:
Traceback (most recent call last):
File "alphatime.pyw", line 61177, in <module>
File "alphatime.pyw", line 53970, in place_menu
NameError: global name 'sys' is not defined
if I try sys.exit, and then:
Traceback (most recent call last):
File "alphatime.pyw", line 61177, in <module>
File "alphatime.pyw", line 53970, in place_menu
NameError: global name 'quit' is not defined
if I try just "quit()". I've heard about 'Raising' things like a need to close the program, but I'm not clear what that means (I'm new to Python) and how I would go about doing that.
So, my question is two-fold.
Firstly, is there something I can put in loops for recognizing keypresses something that will recognize the 'X' being clicked, and close?
Secondly, is there an appropriate command that will just close the program? I cannot figure out why these commands don't work, and I've had quite a few complaints from people using the program that it crashes, or they have to ctrl-alt-del it, or whatever. I believe
import os
try:
os._exit(return_code)
except:
pass
would work, but at this point, I'm not sure I'm competent enough at python to deploy it appropriately. Thanks in advance!
did you by any chance
import sys
because that should work!
NameError: global name 'sys' is not defined
Before you can use sys.exit(), you must import sys.
That's the best way to exit the program. Function names that begin with _ are considered internal, and should not be used unless you are really trying to do something weird.
I am working with a graphics module called cTurtle, which builds upon TKinter. Each controllable 'Turtle' has an image assigned to it with TKinter. I am trying to add a method to the module that will allow me to change the layering position of a given 'Turtle'. Or to put it another way, i want to add a method that will allow me to put a given image on top of the displaylist. When i call the method i have made, i get this error
Traceback (most recent call last):
File "C:\Documents and Settings\login\Desktop\pYTHON EXPERIMENTS\canvastest.py", line 22, in <module>
bob.visUp()
File "C:\Documents and Settings\login\Desktop\pYTHON EXPERIMENTS\jTurtle.py", line 2017, in visUp
titem = self.turtle._item
File "C:\Documents and Settings\login\Desktop\pYTHON EXPERIMENTS\jTurtle.py", line 542, in _visUp
def _visUp(self, item):
File "<string>", line 1, in type
File "C:\Python32\lib\tkinter\__init__.py", line 2325, in type
return self.tk.call(self._w, 'type', tagOrId) or None
_tkinter.TclError: invalid command name ".16847312"
Does someone recognize why the function is rejecting what i passed to it? The number in quotes appears to be an object id, which should work.
EDIT
well, i did myself a great disservice here by not pasting everything involved. I coded these new methods several days ago, and have been trying to debug since. Turns out i coded them right the first time. The problem was in how i called them. I added the visup() test line after exitOnClick(), meaning that the widget had, in fact, already been destroyed.
But, hey, i coded it right the first time! sorta...