I use PyGame for creating games, but I noticed that the programs ran a lot slower on macOS than on my Raspberry Pi. My original solution was to install Ubuntu alongside macOS on my computer, and that worked. However, I would rather only have one operating system on my computer. Does anyone know why PyGame is so much slower on my mac when running macOS?
If it would help, I can send code. However, I have multiple PyGame programs and they all do the exact same thing, so I figured that it was most likely not the fault of the code, but I could be wrong.
Any help is appreciated, thanks.
P.S. When I say slower, I mean that it is running at about 30% of the speed on macOS than it would on Ubuntu.
Pygame is based on the SDL library. It supports using various rendering backends, such as OpenGL and metal. According to this answer (and the comment), it seems that the metal renderer might perform poorly on mac. Sadly, according to this issue, it seems that in most versions of pygame, it uses metal as the SDL backend for mac, and provides no way to change that.
There is the pygame.OPENGL flag you could pass to pygame.display.set_mode(), but I'm not sure exactly how it would affect anything. It might be a good idea to play with the other flags listed here.
I'd recommend you to open an issue on pygame's official github repo with the necessary details. Also, as a workaround, you could clone pygame, change the default renderer on mac to OpenGL, compile, and see if it improves anything. You can use the issue I mentioned above to understand where you should start.
Try running your game in full screen mode
pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
MacOS is generally slower
Unless you can install a second RAM stick it will always be that way
Related
How can I use an analog joystick in Python on Linux? I come from a C++ background, where I used joystick.h to read events from /dev/input/js[x]. Is there a python wrapper around this I can use, perhaps? I don't really want to have to use a huge library like pyGame or SDL?
This gist worked for me on Ubuntu 15.04 without modification.
There is evdev, It's only for Linux, and it seems to be able to do much more than just handling joystick. I've never tried it, though.
I spent some time looking for a library to only read joystick in a cross-platform way, but didn't find any, and I've ended up with pygame (only initializing joystick and event modules) in my projects.
Now (2016+) there's a new sufficiently multiplatform Python module called "inputs" that you can find on GitHub or install from Pipy
It can read joysticks, controllers, keyboards and mices and seems to offer a good support for all their features, including vibration where available.
This topic is in response to a problem I've been having getting Pygame to be set up correctly on my computer. I have Windows 7, Python 3.3 and "64-bit" Windows (now I know what a bit and a byte are, but I don't really understand the implications of having a "64-bit" computer) I'm proficient in Python but know nothing about binaries, dependencies, registries or other such internal/system-level structures; not that I'm not interested, but at the moment most of what goes on is essentially "over my head".
But anyway, with that said, the problem I've been experiencing is basically that I can't install pygame. I've been over several versions of the same question (on Stack Overflow and other places on the web), and I've attempted to install pygame countless times. Sometimes it seems to work fine until I attempt to use it (the installation appears to have been successful but Python gives me errors when I try to use pygame), or I get something about Python 3.3 not being in my "registry" (which from what I read appears to be another OS-level/internal structure for those who understand "the base code of the universe"). They could actually develop a series of tutorials on just the installation process. :)
But all joking aside, I am at a loss here and considering just giving up on pygame. So my question would be, is there any way to use what's already installed (Python's libraries etc.) to develop games? If not, do you know of any alternatives that don't require the same level of experience to install? I've Googled around but everything I've found about game design in Python leads back to pygame. Thanks in advance.
To save yourself pain, just use 32bit python, and 32bit pygame. If you mix 32 and 64 bit, it will not run correctly. That's probably the problem you're having.
Since you have python 3.3, you would use https://bitbucket.org/pygame/pygame/downloads/pygame-1.9.2a0.win32-py3.3.msi
You shouldn't have to edit the registry or your environmentvariables unless something goes wrong.
As mentioned previously, tkinter would offer a solution. For example, this was created in tkinter (http://www.youtube.com/watch?v=RHxLkNryOzI)
The pygame downloads page hasn't been updated for a while and is incompatible with python 3.x. Newer versions of pygame can be downloaded here.
I'd personally use pygame as there's audio support as well but tkinter could be used.
I have this question in my head for over a year now. And I guess you guys may have the answer.
In some Python GUI app, I need to display a video stream.
I need to record some part of this stream to reread it later.
Moreover, I need to make this python application multi platform (OSX, GNU, Windows)
I am open to many solutions :
Connect the camera to a stream and read the stream with the python app. (RTP + VLC could do the trick)
Use Phonon to read the camera
Create an abstract class to define differents reader and use Quicktime, Win32 or GStreamer in function of the OS.
What is your experience, what would you use to do that ?
I've looked into this periodically as well, and it seems the complexity of the underlying task is just too high to have a simple shortcut abstraction library for your topic question. I would suggest using pyopencv for the specific task you articulate, however. It has a class for webcam input/capture which works across platforms and has a reasonable user-base, in python, posting examples. The latest is 2.3.1 and quite recent. You can get a windows version of it, compiled for you, on the unbelievably helpful site (not mine, just saying):
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Since you ask for experience with a few libraries, I'd say: gstreamer worked for me on linux but was a huge pain to setup on windows and didn't work for me. This was quite some time ago and perhaps it's working better now. vlc.py is a simple library to test and see whether vlc would work for you. It doesn't work on 64 bit windows platforms at the moment; not sure why, but it seems many have reported similar errors, so it depends on how much cross-platform support you need.
Unfortunately, this is not easy to do. I've written most of a program that does video recording/playback on the 3 major desktop OS's. The state of video playback/recording in a "out-of-the-box" way is still unsolved for cross-platform, other than HTML embedding. This has a lot to do with the fact that:
Codecs are proprietary
OS's don't support common codecs
ffmpeg and similar projects have licenses that require you to release your source code if you include them in certain ways
A lot of the video playback players that exist are each rewritten by hand to handle each frame, buffering, streaming, audio sync'ing, and the like.
So you can go with HTML, or you can suffer through the cross-platform issues with the following coding libaries:
Python mplayer
Python vlc
Python opencv
Python pyaudio
Python pyside/pyqt phonon or qtmultimedia
Once you get it working on one development machine, expect it to break when it comes to installation on the end-user machine (distribute via: pyinstaller / appdmg / apt / chocolatey / Inno Setup )
On OSX, brew still has a lot of issues with this, but macports works better (I still had to do a lot of patching)
Linux is by far the easiest.
Windows is in-between the to as far as difficulty
I'd be eager to hear how iOS / Android / Windows RT / Kindle are
The problem is not unique, as even Netflix has yet to have a cross-platform video app: https://www.quora.com/Is-Netflix-building-an-app-for-the-Mac-App-Store?share=1
I'm using pygame with python 2.6 right now, But I want to use python 3.1.1 instead. The normal pygame only works with 2.x, but the subversion ones work with 3.x I think. But what about pgreloaded? Is that useable yet? The normal pygame actually works with 3.1 too, but not for os x (at least there isn't a download). Does anyone actually use pgreloaded or subversion pygames? So anyway, should I use pygame subversion, pgreloaded, or stick with the current pygame? I don't really care about being compatible with other things or distribution.
Thanks!
EDIT: Ok, I got rid of python 2.6, installed 3.1, used svn command to get pygame, tried running python3 setup.py, didn't work, changed raw_input in setup.py to input(), worked, now my pygames (that were so simple that they work the same under 2.6 and 3.1) run with python 3.1. :) I didn't get pgreloaded because there's no documentation for it.
Just stick with Python 2.6.
pgreloaded has documentation - there is even an own package at http://code.google.com/p/pygame/downloads/list.
I think JD's link to pgreloaded doc is out of date, try this one:
http://wiki.pgreloaded.googlecode.com/hg/documentation/index.html
Or consider using Pyglet (http://pyglet.org/), which is a thin wrapper around openGL, esp. made for games. It works pretty well, documentation is reasonable, but it of course lacks the massive userbase that Pygame has. It is more mature than PGreloaded imho.
I'll be taking a Python-based computer science class next semester using my MacBook Pro. It will be centered around a custom-designed package for this class. The problem is that this package is being sponsored by Microsoft Research, so it was obviously designed with Windows in mind. Supposedly, it runs on Mac OS and Linux too, but they say they don't officially support Snow Leopard whatsoever.
My concern is that there will be some sort of miniscule differences between the Python code on a Mac and on a PC. The homework is submitted online, and is graded for results. Apparently, they don't actually look at the code itself.
Is this a concern? Should I install Windows in a VM/partition and be done with it? Or should I stay where I feel most comfortable? After all, switching back and forth constantly would be a huge hassle. Thanks for your help!
If the class expects the code to run on Windows then I would install a VM with Windows on it since it is possible that some things may not work quite the same way (especially if you are doing system-specific things like file-system access or executing OS commands).
Classwork/homework always goes smoother when you have the exact same environment as the professor and the rest of the class.
Definitely start with Mac. If it turns out that it really does need Windows, you can switch once you're sure. But Python development is definitely more natural on a Unix-based machine.
Most online graders will let you submit multiple times, and the first assignment is usually easy, so you should know pretty quickly if using a Mac is causing you problems. In the meantime though, you'll have a much smoother ride doing Python on a Mac than on Windows.
If they will be testing your code on windows then you really need to be targeting that platform. However if you feel more comfortable on the Mac, do your dev there but also run a virtual win machine so you can test on the target platform. I would suggest the excellent VirtualBox. You can share local folders with the VM, which reduces the pain of switching back and forth, once the VM has python setup you can just hop in and and run the code direct from the directory on the Mac you developed in.
From their site it looks like Mac is fully supported (up to 10.5 -- it's true that 10.6 is different enough to give occasional problems... I haven't upgraded yet even though I did buy a family pack of 10.5 to 10.6 upgrades, as I'm not looking for trouble right now). If you can use a Macbook with 10.5, I'd say to go for it -- the familiarity and extra productivity are worth the miniscule risk that despite all their claims of support something goes wrong (and you can in fact download and start testing right now!). If your Mac options are limited to 10.6, then I'd go for a VMWare or Parallels VM with a Windows (not sure if Windows 7 is fully supported yet, maybe XP is a more prudent option) installation instead.
Develop and test on a Mac. If it works on the Mac, then test it on Windows before submitting. Done this tons of times with my own programming courses, albeit with a different set of languages and technologies.
Go Mac and never go back.
More seriously, a Mac offers UNIX environment, and Windows offers blue screens.