I am very new to Python, but this does not make sense to me, here's an example script:
import pygame as py
import time
py.init()
song = py.mixer.Sound("pineSiskin.wav") # c1Mb/20sec long
song.play(0 , 9000)
time.sleep(8)
song.fadeout(800)
py.quit()
print("quit")
Running this on a Raspberry Pi*, the CPU goes up to 75% and stays there until I restart the Python shell. This soon leads to overheating on the RPi.
Other questions (like this one & other mentioned in link), are dissimilar as they refer to scripts which have not completed.
This link does hint that what I'm seeing is not "normal" behaviour.
Any help to track this problem/diagnostic advice would be useful.
Apologies if I've made a mistake about which forum; tell me and I'll move it!
*Hardware/Software:
Raspberry Pi 3 Model B running
Raspbian Jessie Pixel
Python 3.4.2
accessed via IDLE3 Python 3.4.2 as bundled with scipi & matplotlib
added
this problem turned out to be an OS problem. recreating the Raspbian OS from a new disk image solved it. Now scripts are behaving as I'd expect.
Related
I'm having a strange issue I've never experienced in python before. When I try to import the keyboard module: import keyboard, my program sends a segmentation fault. I have ran the program with sudo and without. Ive reinstalled the package, and it still won't work. Any help?
Also, very important to mention but I am on MacOS Big Sur. I believe the lack of permissions are the source of this issue, however I am unsure how to add them.
Code:
import keyboard
keyboard.press_and_release('space')
Error:
usr#MacBook-Air Program % python3 keystrokes.py
zsh: segmentation fault python3 keystrokes.py
With MacOS you have to explicitly allow your terminal program to 'control' your computer. In this case your terminal is controlling the keyboard.
Go to:
System Preferences -> Security & Privacy -> Privacy Tab.
Then: Select the Accessibility and add your terminal program to the list.
In my case it was iTerm, yours may be different.
Note: I am using MacOS 12.5 (Monterey), but here is the link to Apple Support describing the process in more detail (Specifically for Big Sur)
https://support.apple.com/guide/mac-help/allow-accessibility-apps-to-access-your-mac-mh43185/11.0/mac/11.0
After installing the Pyglet library on my windows 10 machine, I deiced to test if it was working correctly by running a shortened version of the code provided from Writing a pyglet application:
import pyglet
window = pyglet.window.Window(width=640, height=320, caption='window')
pyglet.app.run()
However, when the window was finally displayed, this is what was shown:
To make sure this wasn't an OS problem, I went back and re-read the pyglet requirements. It stated that it would work with Windows XP and greater:
Windows XP or later
Mac OS X 10.3 or later
Linux, with the following libraries (most recent distributions will
have these in a default installation):
OpenGL and GLX
GDK 2.0+ or PIL (required for loading images other than PNG and BMP)
Pulseaudio or OpenAL (required for playing audio)
The problem seemed to be platform specific because Pyglet worked on Linux (Ubuntu 16.04). Finally, after thinking about for a bit, I decied to try running the code from the command line since I was currently running it from the Python IDLE. Sure enough, the code ran and the window was displayed correctly:
I then realized that this was the only difference I had made when running the code on Linux; I had used the command line. Although I cannot confirm this with absolute certainty, this seems to be a problem created simply from running the code in Python's IDLE.
Has anyone else encountered this behavior. Is this a known problem? If so, what's causing it?
I've been trying to install the python library for making games, pygame, in my yocto image of linux for my raspberry pi 2. I have a python code of a game, I've run it in raspbian and it runs pretty slow, but it runs. Now in my image of linux I already have python but I have failed in installing the pygame library. Every time I tried to run the game it says "Error: import pygame", so clearly the problem is in the way I install the library.
I would appreciate any kind of help.
Did you check your PYTHONPATH is set ?
To set it, do:
export PYTHONPATH=/opt/ros/indigo/lib/python2.7/site-packages
You can add this line to your .profile or .bashrc
I recently attempted to install python 3.2 along with IDLE 3 on my macbook pro. I successfully installed python 3.2 (as in, I can run it from the terminal), but when I attempted to install IDLE 3.2 I must have done something wrong because now both IDLE 2.7 and IDLE 3.2 crash immediately upon opening with the message "Python quit unexpectedly", no matter whether I open it through the terminal or through finder. Does anyone know how to fix this? I have installed the correct ActiveTCL package (and reinstalled) and still nothing. I have attempted to reinstall python 3.2 and IDLE 3 but I am not sure whether I did it correctly. Through a good amount of googling I found some people say that it was most likely a path issue but all of the solutions I found were using Windows so I am not sure how to apply that to my mac.
Try renaming or removing the directory ~/.idlerc which is about the only thing used by Python that would in common to IDLE for 2.7 and 3.2. If that doesn't help, state exactly which Python 3 you installed, what version of OS X, and show the stack traces from the termination report.
UPDATE: Based on the crash report you've supplied, it appears that Tk is crashing during its initialization of menu items:
...
4 Tcl 0x00000001013dfa61 Tcl_Panic + 162
5 Tk 0x000000010151c523 TkpGetColor + 383
6 Tk 0x0000000101529a25 TkpMenuInit + 156
7 Tk 0x00000001014ac254 TkMenuInit + 88
8 Tk 0x000000010152c687 -[TKApplication(TKMenus) _setupMenus] + 53
...
I have not seen any reports of a similar problems when IDLE is used with A/S Tcl/Tk 8.5 on 10.7.3 and I haven't been able to reproduce it myself on 10.7.3. However, the Cocoa Tcl/Tk 8.5 is not the most robust framework out there and it may be susceptible to problems when using languages or input methods other than US or US Extended. Another possibility (more likely) is if you are using some third-party menu enhancement application or preference panel (to add colors to menus perhaps). If those suggestions don't help you to isolate the problem, I suggest you ask on the Tcl Mac mailing list (tcl-mac#lists.sourceforge.net, archived at http://dir.gmane.org/gmane.comp.lang.tcl.mac).
If you are running Mac OS X Lion, it sounds like you are being bitten by the saved-state crash. You need to delete the saved state to make the crash go away:
http://osxdaily.com/2011/07/17/delete-specific-application-saved-states-from-mac-os-x-10-7-lion-resume/
http://reviews.cnet.com/8301-13727_7-20083707-263/managing-mac-os-x-lions-application-resume-feature/
I had the same issue. I run OSX 10.8.5, Python 3.3.3 and IDLE 3.3.3 and reinstalling Python haven't been a solution.
I solved any problem removing the ~/.idlerc directory. My problem showed for the first time when I tried to change some Preferences (IDLE->Preferences->General->Startup Preferences->At Startup Open Edit Window), so I suppose that's why resetting my Preferences deleting ~/.idlerc folder have been the solution.
I had the same problem where IDLE would crash after I opened it on my MAC
I ended up updating my computer to OS Yosemite.
and the most updated version of python but it still would shut
the reason it started was because I tried to change the preferences for certain keys.
Resetting the preferences fixed it!
I typed mc ~/.idlerc idlerc2
:)
[Solved] I had the same problem here using:
Yosemite 10.10.2
python 3.4.2
The issue was solved downloading and installing the ActiveTcl 8.5.17.0 version from http://www.activestate.com/activetcl/downloads
Best Regards,
TchĂȘ
I'm getting a Tkinter error even though it was imported and used yesterday. I have a Windows 7 OS and am running Python 2, so I'm not sure what I'm supposed to do at this point. My google-fu is weak today, I can't seem to bring up anything relevant. Any input would be greatly appreciated.
You may want to check if the version of the Python interpreter used to run the script got changed somehow.
import tkinter works in python 3 (instead of Tkinter).
This happens when you most likely have more than one Python installed on your system and you're running the program from a version different from the one you programmed it in.
By default, a Python program on your PC will usually be opened in the latest edition of Python.