Pygame is not running with vscode in Ubuntu 18.04 [duplicate] - pygame

I'm using Ubuntu 20.04.1 LTS. I have installed pygame with sudo apt-get install python-pygame. However, when I run my code using VS code, the python terminal gives the output below:
Traceback (most recent call last):
File "path", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I tried to reinstall Pygame using the same command. Here is the output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-pygame is already the newest version (1.9.6+dfsg-2build1).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
Basically, I already have pygame installed. So what do you think might be the reason? My Python version is 3.8.2.
Thanks in advance!

There isn't a release build of pygame 1.9.6 for Python 3.8.2. Install a development version:
python3 -m pip install pygame==2.0.0.dev10

Related

How can I resolve the "pygame.error: No available video device" error in pygame? [duplicate]

I have this setup:
$ python -V
Python 2.7.2+
$ python -c "import pygame; print pygame.__version__"
1.9.1release
When I run a pygame script, I get this error:
Traceback (most recent call last):
File "/home/santosh/tmp/pygameHelloWorld.py", line 8, in <module>
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.error: No available video device
I am using Ubuntu and have install pygame with apt-get. Additionally I have install all dependencies mentioned on this pygame wiki page.
If you are running Pygame on a UNIX system, like a Linux server, try using a DummyVideoDriver:
import os
os.environ["SDL_VIDEODRIVER"] = "dummy"
From similar experience the most likely problem is something is wrong with one of your SDL packages. Try running the following.
import pygame
pygame.init()
pygame.display.list_modes()
If you get back an empty list, it's definitely because of the packages. Try reinstalling them.
Possibly related:
SDL init failure, reason is: No available video device
SDL init failure, reason is: No available video device in ubuntu 12.04 LTS
This problem might only affect Windows XP. Try adding one of these to your code:
import os
os.environ['SDL_VIDEODRIVER']='windib'
or
import os
os.environ['SDL_VIDEODRIVER']='windlib'
Good luck.
Wild guess - is the DISPLAY environment variable set and/or required by the library, and not available? This could be the case if you're ssh-ing into the Linux machine you're running this on without providing the -X option.
Try the following:
import pygame
from pygame.locals import *
pygame.init()
On Linux you can solve the problem using x11.
Verify that your SDL was built with x11 support, otherwise build it yourself only after that you added some libraries in this way:
sudo apt install xorg-dev libx11-dev libgl1-mesa-glx
Maybe xorg-dev already installs libx11-dev
Build SDL from source and enjoy
I solved it with the three commands below:
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install libsdl1.2debian:i386
I was getting this error while trying to render an OpenAI gym in a jupyter notebook. Following fushan's answer got it to stop erroring, but it only rendered a black image. Looking at https://wiki.libsdl.org/FAQUsingSDL, I figured out that I could use directfb as the renderer. The code ended up being:
import os
os.environ["SDL_VIDEODRIVER"] = "directfb"

Pygame examples not found in Ubuntu 20.04

I want to learn how to code in Pygame (python3.8.5, Ubuntu 20.04). I got pygame installed but it can find the examples. I tried to search for them manually and didn find them either. It seems that the examples were not installed at all.
Here's what I did so far:
The attempt to install pygame with pip failed due to tons of failed dependencies.
python3 -m pip install -U pygame --user
After searching a bit, I found this command, which installed pygame:
sudo apt install python3-pygame
But it fails when I try to run one of the examples:
user:~$ python3 -m pygame.examples.aliens
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
/usr/bin/python3: Error while finding module specification for 'pygame.examples.aliens' (ModuleNotFoundError: No module named 'pygame.examples')
Any ideas what's wrong?
Thanks!
The Ubuntu Package Maintainers have elected to not include the examples in python3-pygame. Tests and docs are also excluded.
You can access the examples from the pygame github repository.

python 3.3 and pip tool installation

Pip3 installation and Python 3.3 on windows vista
I have been using python 3.2 for a short time and I wanted to install pygame and other other packages. At that point I realised that I have to install pip tool as a package manager. In short, in the process, I removed python 3.2 and installed properly python 3.3 and encountered the following problems:
From python 3.3 interactive interpreter:
when I do: pip --version I get:
nameerror pip not defined
When I go Python get-pip.py I get
syntaxerror and the get is in red
sudo python 3.3 setup.py install gives error as well
But I was able to download the get-pip.py script and this script is inside my download manager. Again,there is no pip tool when I checked my python3.3 script directory.
Thank you in advance for your attention
Usually get-pip.py runs.If nothing is working, try the wheel file. Download the .whl file and run:
python.exe pip-9.0.1-py2.py3-none-any.whl
Hope this helps.

Installing Pygame without whl files [duplicate]

Currently unable to install Pygame via pip:
pip install pygame
Getting this message:
Concerned by it being termed an EOF error, is this an error in the module itself?
There's dev versions available as of now. Get them via
pip install pygame==2.0.0.dev6
Pygame is not compatible with Python 3.8 at the moment. I would recommend you to downgrade back to 3.7 and installing with pip there.
pip is doesn't have pygame up.
But there is a alternative that worked for me. https://www.pygame.org/wiki/CompileWindows
Read and follow the steps correctly and it should install.
you also need to update your code to pygame 2.0.0 code because it's only for 3.8
BTW you have to follow the SDL2 instructions since pygame 2.0.0 uses that.
the above commands worked for me today 3-15-20 with Python-3-8-0 on Linux Mint 19
to get IDLE to recognize pygame.
sudo pip3 install pygame==2.0.0.dev6
I also had to update pip first with
sudo pip3 install --upgrade pip
Pygame requires visual studio C++ build tools to install. Ensure you have these downloaded from here.
Open power shell window and make sure your internet is on
Then type the following command
pip install pygame
It will automatically download it for you and also install it
Again make sure your internet is on
I have python 3.8.2 and it worked on my pc

how to install pygobject for python3 in fedora18

i try to install pygobject for python 3 in fedora 18
i read this doc https://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html and i try to install jhbuild after that when i type $ jhbuild sanitycheck
get this error : bash: jhbuild: command not found...
i try to install with yum , i install "pygobject3-devel" but this not work with python3
in fedora 18 default python is python2.7.3, i install python3.3.0 with yum and test a first demo code :
#!/usr/bin/python
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
after give chmod +x for this python file can run with this command "./test.py"
and if i try to run with python (with out use #! ....) and type this command "$python test.py" that run and work without any problem but when i type this command "$python3 test.py" i get this error :
Traceback (most recent call last):
File "test.py", line 2, in <module>
from gi.repository import Gtk
ImportError: No module named 'gi'
have any idea ?
thanks
Try installing pygobject3 instead of pygobject3-dev (as a matter of fact, it seems that pygobject3 is already installed in a vainilla installation of Fedora).
After installing that package, you should be able to open your interpreter (python2.7) and do:
from gi.repository import Gtk
If you want to use python3 (I didn't understand if you meant that you tried to use python3 or you want to use python3), it seems that the gnome instrospection bindings are not yet available, according to this page that summarizes the state of different packages python3-related that are being on the works.
EDIT: I just tried installing python3-gobject (which should be installed when installing pygobject3, but it doesn't for some reason) and it seems to be working aswell on python3.