Pygame 1.9.6 not loading in Python 3.8.1 [duplicate] - python

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.

Related

Python cant recognize my installed modules [duplicate]

I currently have Python 3.10.5 and pygame 2.1.2.
VScode 1.70.2
Versions
For some reason there is the following warning: Image for warning
Import "pygame" could not be resolved PylancereportMissingImports
Even though I have the pygame library installed using "pip install pygame".
And when I run the file by pressing the "Run Python File" in the right top corner, it runs perfectly without an error. It even uses the terminal to show whatever I am printing.
My issue here is the warning and that intellisense for pygame isn't working.
What can I do to fix that.
I already tried to make a clean install on everything, python, pygame, even VScode. Nothing.
Try to reload vscode (by command pallete or just restart the app), reinstall pygame and make sure python path is selected. Also it is worth to trying selecting interpreter. Open command pallete and type: Python: Select Interpreter, then select your python version.
yes as the #NoBlockhit stated probably you have 2 different python versions installed and vs code choses the one without the pygame library (https://code.visualstudio.com/docs/python/environments) if you scrolldown it shows you how to chose an in interpreter...

no module of pygame error about visual studio [duplicate]

This question already has answers here:
ImportError: No module named 'pygame'
(25 answers)
Closed 2 years ago.
there, I am newbie, and I am learning pygame, but my Pycharm and Visual studio in Mac always have something wrong of pygame. I have install the pygame with pip, and it is say, 'Requirement already satisfied: pygame in /usr/local/lib/python3.9/site-packages (2.0.1)'. And today I open the Visual studio, 'ImportError: No module named pygame'. Also, the pycharm is there every time if i do a new project I must re-setting the file again to install the pygame packet? why Pygame cannot be a default module but have to set again and again. Because I am living in China and first time to run code and mac Os, if there is any tutorials for me to set the pygame, pycharm, and visual studio, and so much thank you.
Pycharm projects have a virtual environment that may not have access to the same packages as your host system. To make sure pygame is installed on the virtual environment, go to
File > Settings > Project: ____ > Python Interpreter
It will list all packages on the virtual environment. To add pygame if it's not there, go to the + sign in the bottom left corner, type in pygame, and hit Install Package

How does one successfully download AND import pygame?

the problem:
as part of my studies, i have tried to download PyGame for my own independent project. I've currently downloaded 1.9.6, as well as currently owning IDLE version 3.8. i have imported it many times:
folder.
on one occasion , i placed it in its own separate folder with the coding file in another internal folder
when importing it into a new python script, the result was that there was "no module named Pygame", even though it was in a file containing the recent edition (this method was used successfully to download Tkinter).
I also tried making a python script outside the contained folder like this
this,too had the same result.
Any idea what exactly to do?
any more important information
The computer type is a MAC 10.13.6 and the IDE is IDLE. As previously mentioned, the downloaded version is version 1.9.6 and i have not a clue what how many bits my computer manages. Apologies that this is probably one of MILLIONS of the exact same question answered.I've tried at least 2 of these solutions.
First you need to make sure that you have pip installed. Type pip in your cmd (command prompt) and if you get no errors you are fine. If you have errors follow this link to get it. If you are stuck on that link - basically all you need to do is uninstall python and then when you are installing it again tick the box that says:
Add Python 3.5 to PATH
Now just finish installing python.
Next you need to install pygame with pip install pygame in your cmd - run it as administrator just to be safe. If you receive errors try updating pip with python -m pip install --upgrade pip. Now create and save a new python file. Import pygame in that file by using the code import pygame. The output should be:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Now you are free to code in pygame! I hope this helped.

Pygame window not showing on macOS Catalina

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:

PyGame not working in Eclipse using Python3.4

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)

Categories