Running:
macOS Catalina 10.15.1
Python 3.8.0
Pygame 1.9.6
IDE - Visual Studio Code 1.40.2
When I launch the Pygame test:
python3 -m pygame.examples.aliens
The music begins playing and after about 5 seconds the app closes. No window appears. The icon in dock shows up until it's closed.
The same thing happens with a basic test code such as
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
There are no error messages in the terminal.
Anybody have this issue? I've tried reinstalling both Python 3.8.0 from the website (as recommended in a different thread) as well as Pygame.
This solution was given by furas in this comment:
Maybe install Python 3.7. Python 3.8 is very new version and many modules are not ready or not tested for this version.
This works on Python 3.7.8.
After several trials I have found out that the problem can be solved with one of two ways, You may try each solution one by one as one have worked with some friends and other have worked with others.
My system info:
macOS Catalina 10.15.6
Python 3.8.5
All solutions depends on trying latest Pygame developer versions (knowing many would say its not final release and it might be not stable but i believe this is much better than downgrading your macOS version).
Solution A:
At Terminal, try installing Pygame dev 4
pip3 install pygame==2.0.0.dev4
This solution allow me to work with most codes but when I try some samples online
it give me this error "Sorry, extended image module required"
Solution B:
At Terminal, try installing Pygame dev 4
pip3 install pygame==2.0.0.dev6
This time it works perfectly form we for all online and offline codes
To Test result try this sample
python3 -m pygame.examples.aliens
Here is a screenshot for the previous sample after fixing the issue:
Related
I recently got a new computer (Mac 14" Monterey OS) and reinstalled Python, PyCharm, etc. Everything seems to work okay except when running turtle Screen(). The code finishes with exit code 0 (no errors) but when the launcher pops up its just a tiny black screen that flickers. Doesn't even display the title correctly anymore.
It seems I've tried everything: re-installing Python, installing a later version (Python 3.9 vs 3.10) and reinstalling PyCharm, making sure the interpreter is okay. Nothing is working. I've spent about 2 hours googling to find a solution. I'm stuck and frustrated since I am supposed to be doing a coding workthrough with a company this coming week.
Here is the code that should be running:
import turtle
screen = turtle.Screen()
screen.title("States Game")
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
def get_mouse_click_coor(x, y):
print(x, y)
turtle.onscreenclick(get_mouse_click_coor)
screen.exitonclick()
And here is an image of what is going on...
please click this link to see image
Check your python interpreter version.
I have the same issue when it uses python3.8, after upgrading to 3.9. It works perfectly.
You need to install Python yourself instead of relying on the Python provided by macOS. I downloaded latest macOS 64-bit universal2 installer from https://www.python.org/downloads/macos/ and it works. (make sure you create new interpreter in Pycharm, using the newly installed python)
I think the cause of the issue is that the tkinter package has issues for the builtin python.
I installed pygame through cmd using pip install pygame which can be seen in the ss. For some reason im unable to import it in my main.py file. Is there some way for me to fix this?(screenshot of terminal and vscode file)
I faced the same issue, but I had used the terminal. What I had done:
Deleted pygame which was installed via pip.
Installed it from the official website.
Then imported pygame. It fixed the issue.
I use linux
Alternatively, you can open the app installer of your device and search "pygame". Hopefully the module shows up.
I'm using pygame to write some games on my macbook pro 2018, and using the python in anaconda, the FPS is very low, after some research I found this solution Pygame application runs slower on Mac than on PC, it's says set the python to "Open in Low Resolution", I did the first 5 steps, but the python3.6 in anaconde dose not end with .app, so it doesn't have the "Open in Low Resolution" checkbox, can anyone tell me how to deal with this? many thanks!
OK, I solved it,
TLDR
pip uninstall pygame
pip install pygame==2.0.0.dev6
seemd the SDL used by pygame can't work correctily on MacBook, and pygame2 use SDL2 that doesn't have that issue
This question already has answers here:
Problems getting pygame to show anything but a blank screen on Macos
(10 answers)
Closed 2 years ago.
Really strange issue here. I have a 64bit copy of Python 3.8.1 on my Mac (Catalina 10.15.2). I have successfully installed pygame via pip3 install pygame. Every time I run Python3 and import pygame, I get the successful message of hello from the pygame community....
However, if I run any program that requires an import of pygame, the icon for my python launcher just loops and loads for an infinite amount of time. I get no error messages. I literally get nothing. No opened windows. Just a blank line on the terminal (and IDLE terminal) window after the hello from the... message.
I have on my Mac taskbar a bouncing icon of Python, indicating that it is loading. But nothing happens? I've tested this on every instance of a pygame program with no success. Even the Aliens example embedded within the program does not work.
I had the same issue. Did this in Terminal:
python3 -m pip install pygame==2.0.0.dev6
and in PyCharm I installed pygame package once more into project interpreter with "Specify version" option selected for a specific version: 2.0.0.dev6
Then it started working.
I am using Linux Mint 17 (Ubuntu 14.04) and already got pygame 1.9.2 working in Eclipse on my Windows PC. Now I also installed it on this machine, but it doesn't work. Thus there is no apt-get for python3-pygame I downloaded the source from https://bitbucket.org/pygame/pygame and built and installed it without getting errors.
When running the following on the command line I receive no error:
import pygame
pygame.init()
If I try the same in an Eclipse PyDev project I get the error: "Undefined variable from import: init".
First I thought that my Interpreter was not set up correctly, but the path where pygame is installed is added to the libraries (/usr/local/lib/python3.4/dist-packages). I realized that for Python2.7 pygame is installed in /usr/lib/pytho2.7/dist-packages instead, but this directory doesn't exist for python3.4 on my machine.
Since it seems to work on the command-line it must have something to do with the Eclipse or Pydev settings, right?
UPDATE:
Ok, now things are getting really confusing. I found out that pygame indeed is also working from within eclipse if I run the project, but only giving me these error messages for eg. pygame.init(), pygame.QUIT, pygame.K_ESCAPE, pygame.KEYDOWN. I find it very strange, because pygame.time.Clock() or pygame.display.set_caption() don't give error messages. So I only get undefined variable from import errors (also see here How do I fix PyDev "Undefined variable from import" errors? ).
Use sudo pip3 install pygame, pip3 should work assuming you have python3 and setuptools installed.
You can install pip3 using sudo apt-get install python3-pip and then use sudo pip3 install package_name to get whatever you want.
The only thing which worked for me (I spent two days now finding out what the problem is) is to add "pygame" to the forced builtins for the Interpreter (Window -> Preferences -> PyDev -> Interpreter -> Python Interpreter -> Forced Builtins Tab -> New -> pygame.
This is only a workaround, but at least I am rid of those errors for now and auto-completion still works. I didn't find any other solution that worked for me so far.
For me the problem was resolved by importing *.
instead of:
import pygame
try this:
from pygame import *
now instead of calling init() by saying pygame.init() just use init()
also you should not have to explicitly call using pygame. for the most part.
NOTE: after playing around with this in Eclipse I did end up having to use both:
import pygame
from pygame import *
for whatever reason one of my functions only works if I have pygame.even.get()
but the test of my code does not need to use pygame.
(I am sure there is a perfectly good reason but I am still very new to python)