install and use pygame on Mac Yosemite - python

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.

Related

cant import pygame using vscode , python 3.8 , pygame installed from powershell

so im using visual code,
have python 3.8 installed and i installed the pygame package from powershell,
yet when im writing pygame code it gives me the next error:
" ModuleNotFoundError: No module named 'pygame' "
tried everything for hours cant get it to work
help will be apriciated <3
images:
What you also can do is to download pygame to your folder and than run the command python setup.py. This should install everythin correctly. If you still have trouble using pygame you can use the files in src_py from the download:
import init #instead of pygame.init()
I hope I was able to help.

Python Pygame Error

so i've recently installed pygame because i want to start programming with it. Before writing code, i decided to just make sure its running fine by testing it in IDLE.
i ran
import pygame
no error
i ran
pygame.init()
and got the following error
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
pygame.init()
AttributeError: module 'pygame' has no attribute 'init'
by doing some research i found out that it may be messing up the path, so i tried
pygame._path_
and got a similar error
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
pygame._path_
AttributeError: module 'pygame' has no attribute '_path_'
and i can't figure out whats wrong. i've tried solutions in other questions but nothing works
im using
Windows 10 Home
Python 3.5.2 32 Bit
Pygame 1.9.2a0 for python 3.2 (but after looking up if it would work with python 3.5, i found resources saying it would)
i tried installing the 3.5 version as a .whl but it had its own host of problems and just decided to use the installer. is the error because of the mismatch between python versions and pygame versions, or is there something else i can try?
I have tried the following
pygame._path_
there is nothing else named pygame.py that would confuse the path
i used the installer
i made sure there were no other versions of python/pygame installed
So are there any other solutions beyond the ones that i have tried to get this one working?
Thank you for your time.
EDIT 1: I have made sure that the only directory named pygame is the module.
to finding the pygame path:
Magic methods have two underscores on either side of them.
to the lack of pygame.init():
different software seem to be able to find different parts of pygame, because PyCharm cannot locate that function, but when running off the command line it operates perfectly. It may just be a fault of idle. Try running from the command line or double clicking the .py file, assuming it is associated with the interpreter. If that doesn't work, run the command
python -m pip install --upgrade pygame
Have you installed pygame correctly.
Put this in your cd (command prompt) to check if you have installed pygame properly
py -m pygame.examples.aliens
If it gives a error then you should use the pip install function
py -m pip install -U pygame --user
If everything fails you can install an IDE. I would recommend pycharm https://www.jetbrains.com/pycharm/download/#section=windows
It is a free IDE and you can install pygame from there for a project
File --> Settings --> Project:(Name) --> Project Interpreter --> pip --> type pygame and install package.
Pycharm pygame installation

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

How do I import colors?

Can anyone explain to me how to import the Python colors? This is for a programming assignment, but I'm stuck here and can't find tutorials online.
I tried from livewires import games, color
File "/Users/username/Desktop/Programming100/PhysicsLab/PhysicsCsLab.py", line 2, in <module>
ImportError: No module named livewires
I wanted to color shapes such as ellipse, rect, etc., but I don't know how that can be made possible.
Edit: I don't know if this matters or not, but I'm using CALICO.
This just means that you haven't installed the package. Or you have installed it, but the python interpreter you're using the run the script does not does not have it installed. This can often happen when pip is defined for one python interpreter in particular.
If you have not installed it then you can do so using:
pip install livewires
If that does not help, you're going to go into your interpreter's location, go into Scripts and then use pip install livewires.
You don't have the python's package named livewires. You can install it via pip like so: pip install livewires.
Do you mean terminal colors ?
You can try colorma - https://pypi.python.org/pypi/colorama and it works great!
I am not sure how will you draw shapes though. You can try using curses - http://docs.python.org/2/library/curses.html

Installing Python/PyGame on mac

I've been trying to install PyGame with little success. I downloaded the
pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg
version of PyGame from this link and installed it using the wizard, but when I typed import pygame into the IDLE I got the following message.
$ import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
What did I do wrong?
Also, what are the prerequisites for PyGame? I'm doing all this on a new computer and I've hardly downloaded anything.
I'm running OS X Version 10.8.2.
I know this thread is a little old, but thought I'd share my experience on this subject...
I'm using a 64-bit MacBook Pro running OS Mavericks and python 2.7.
Steps:
If you've installed a few different versions of pygame while trying to get the darn thing to import and work successfully, make sure you delete/uninstall all of these to get a fresh start. I did a simple search in the terminal to see where all of the various pygame folders where located:
In Terminal: sudo find / -iname "pygame"
The results show a list of all the pygame directories, these are the folders that you want to delete. Note, I created a new tab in terminal to do this so I can reference the directories from the search on the previous tab and easily copy each directory without having to do another search to remember where they are:
In Terminal: sudo rm -R -i path/pygame
Also note, you can take the -i out of the above code and it won't confirm the deletion of certain files, but BE REALLY CAREFUL when deleting full directories from the terminal.
Once your machine is clean of all previous pygame installations, make sure you have python 2.7 from python.org, NOT IDLE (default Mac Python Interpreter)! This is very important. I use PyCharm and it rocks! Also, choose the version that works on a 32-bit machine and 64-bit machine - this way you won't have issues with the pygame 32-bit installer on your 64-bit machine. I tried same installation process but with the 64-bit only python 2.7 installation and it didn't work. Link provided below:
Download 32/64-bit Python 2.7
Next, download the 32-bit pygame file for OS X 10.3 and beyond and run the mpkg file created from the dmg. Link provided below.
Download pygame 1.910 release for python 2.7
You should now have a working pygame installation in your python 2.7 package library. Enjoy.
Did you install python from python.org? Or use the one that came with OS X?
If you used the one supplied by Apple, you must download the one from python.org first, then install using that package. Or you can try the Lion-pygame package (the link is at the bottom of the Macintosh section of the download page), but it may be incompatible.
Did you download python 64-bit or python 32-bit?
This can cause major problems if you don't have the right one, if you have 64-bit you can download pygame 64-bit from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Categories

Resources