How do I import pygame on 3.7.1? - python

I'm running python 3.7.1 on my MacBook and it has been running perfectly until I tried importing pygame. I'm taking an intro to python class and we always just do from module import *. When I tried to do that same format with pygame I just got an error ModuleNotFoundError: No module named 'pygame'
What should I do about using pygame or should I just forget using pygame altogether
I'm new to python and the reason I'm trying to use pygame is that I'm making a game where the user controls a .gif or a spaceship and tries to avoid asteroids. All of my code is solid accept for the collision detection. Everyone seems to point me towards using pygame but i can't get that to work. Should I continue to use pygame and if so, how do i fix my problem? Should I drop pygame altogether and just try collision detection a different way; (if so, what other way?)

pygame is not bundled in standard python.
to install pygame in Mac, see
Mac installation from pygame.org
Also, from module import * is not a good practice if you're using more modules,
which will causes class name conflicts.

Easiest way to do it - forget 3.7.1 go on the Python website (linked) and download 3.6.7 ther when your setting up click add to PATH then you need to install pygame ( save it locally near where python is saved) then go on to terminal by going to finder and clicking applications and search terminal and type pip install pygame if there is anything you are confused about just ask (:
Path button

Related

install and use pygame on Mac Yosemite

I installed Pygame on my mac using Anaconda.
pip install pygame
>>>Requirement already satisfied: pygame in /anaconda/lib/python3.6/site-packages
The thing is, I do not know to use it now. When I run a simple file from my code editor it says:
File "/Users/julien/untitled5.py", line 1, in <module>
import pygame
ImportError: No module named pygame
any advice ? I tried to run pygame using spyder from the Ananconda Navigator bun it does not seem to work either.
The issue is that your IDE is looking in the wrong places for pygame. To see where it's looking for packages, run this script in the console for that IDE:
>>>import sys
>>>sys.path
This will show a list of paths where python looks for packages. /anaconda/lib/python3.6/site-packages won't be there, which is why you can't import it. What IDE are you using? Most are able to change their settings so that they can import from different places, see if you can do that, and put /anaconda/lib/python3.6/site-packages as part of the path.

Pygame on Yocto

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

How to import pygame, pyperclip?

I am fairly new to python but am having issues importing certain packages within my code. I try to import pyperclip aswell as pygame. I've installed them both manually and I've tried importing them using import pygame and import pyperclip and I get
"no module named 'pyperclip'"
and the same thing for pygame. I've tried opening by putting just import pygame and saved it to run it in the interactive shell and I've also just tried typing it into the interactive shell.
I'm running linux mint 17.3 and python 2.7.6
Has anyone else had this issue?
Any help would be appreciated. Za
I had the same problem. I am also new to Python and programming. I tried about 100 things, but what worked for me was typing the following in the command shell:
pip install pyperclip
That was it. However, I was using Windows' command module, so. . . you know. But it's worth a shot!
This link might help, too (it has Linux instructions, etc): https://github.com/asweigart/pyperclip

My pygame game does not start as it throws up an error, how do i fix it?

This is supposed to pull up a pygame window.
All it says is no module named pygame, how can I possibly solve this?
pygame.init()
screenwdith=800
screen=pygame.display.set_mode((screenwidth,400),0,32)
You will have to install pygame.
See http://www.pygame.org/download.shtml
remember to use the right one for your version of pygame
then say: import pygame at the beginning of your code.
Install the correct version of pygame for your version of python
http://pygame.org/download.shtml

PyCharm autocomplete does not work with pygame

I've just installed PyCharm Community Edition 3.4.1 and tried to make a simple pygame project in it. I found that code completion runs in a weird way. In this case:
from pygame import event
event.
when I type event. a completion popup with event methods shows immediately. But in the second case:
import pygame
pygame.event.
a popup contains only object methods.
How can I learn the autocomplete tool to look deeper into the library?
Other than creating your own skeletons, you can't. You can make pycharm a little better a code completion if you enable the following:
But other than that, you're out of luck. Python is hard to make code completion for because its a dynamic language, and stubs (skeletons) don't exist for everything.
I tried Daid's answer (removing the try/except in init.py) and it didn't work, but it was very close! Here is how you can fix it specifically for pygame:
Go to your pygame folder and open init.py in a text editor
Navigate to the import section with the try/except clauses (around line 109)
Change the format from import pygame.module to from pygame import module for the modules you want
For example, change
try: import pygame.event
to
try: from pygame import event
Restart PyCharm and it should work :)
It has to do with how pygame is constructed.
The:
python\Lib\site-packages\pygame\__init__.py
File contains the following construction:
try: import pygame.cdrom
except (ImportError,IOError):cdrom=MissingModule("cdrom", geterror(), 1)
Which allows missing imports. However, this confuses pycharm. Removing the try+except will fix the pycharm auto completion.

Categories

Resources