I'm working off the latest Mac OS trying to set up my programming environment. Right now what I want to do is to get Pygame working with Pydev so I can do my Python programming from Eclipse. What I've done so far is installed Python 2.6 from python.org and then installed pygame 1.9 from the site.
What happens is that when I try running Python from the command line, I am able to import pygame without a hitch, but when I try to do the same thing from Eclipse, it doesn't work.
I think it might be because Pydev doesn't know where to find Python, in which case I would like some help on how to make sure it's pointing to the right one.
Thanks!
I work with Eclipse on Windows, but I believe that the Mac version eclipse should be the same.
In Eclipse,
- click Windows > Preferences,
- expand PyDev from left side,
- find Interpreter - Python,
- switch to Libraries tab,
- click New Folder on the right hand,
- navigate to your pygame path, and
- click Apply and OK.
Turn to your Python project in eclipse,
- right click on it,
- choose PyDev - Interpreter/Grammar,
- choose Python as Project type,
- choose 3.0 or your correspond Python version from Grammar,
- at last make sure the Interpreter you are using is the same as the one you just configured.
Build your project from eclipse, and it should work.
In Eclipse, Window->Preferences, expand Pydev and choose Interpreter - Python. Then specify your python path. Try first by clicking "Auto Config" to auto-locate your python installation. Then click Apply and Ok.
Make sure this much works by creating a new Python project (without worrying about Pygame yet).
I tested these instructions from Eclipse Helios on Windows. Hope it works for you.
http://www.vogella.de/articles/Python/article.html
If autoconfig is not finding 2.6 you can add it manually at Preferences/PyDev/Interpreter - Python. There you have to press New and set the path for your Python executable.
For Python2.6 the path is: /System/Library/Frameworks/Python.framework/Versions/2.6/bin/Python2.6
For Python2.7 (and higher), the path is different:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Those paths work on OS X 10.6.8, might change for other versions.
Do what the people says, and if that does not work, make sure that you have downloaded the development package.
On menu Window > Preferences > PyDev > Interpreters > Python Interpreters
If your python interpreter config have a pygame and don't work, try to put on force bultins the new keyword "pygame"
Python part
- Install Python 3.5.2 32 bits (From python.org)
- Download the right pyGame library for 3.5.x 32 bits (It will be pygame-1.9.2b1-cp35-cp35m-win32.whl)
- Open the system console and go to the folder where the library was download.
- Write in the console: pip install pygame-1.9.2b1-cp35-cp35m-win32.whl
This should install the pygame library.
Note: If the pip version is not the last one, upgrade it. (In this step you should know how, just pay attention.)
Eclipse Part
- Go to Window>Preferences>pyDev>Interpreters>Phyton interpreter.
- In the Python interpreters part, click Quick Auto-Config.
Note: If you want to do this manually, you should know the path where you installed Python and search for python.exe
- Some libraries should manifest in the libraries tab. Click apply.
- In the libraries tab, click New Folder.
- Search for PyGame installation path (In my case, C:\Python\Python35-32\include\pygame but it's always on Python installation path plus include\pygame, ok?)
- Click Accept.
- Go to Forced Builtins tab. Click New... and add 'pygame'.
- Apply again ! (You should know that I do this only for safety. You can apply just one time.
- Click OK.
Test
- File> New> Proyect...> PyDev> PyDev Proyect.
- Click Next
- Complete the Proyect Name. On Grammar Version combobox, select 3.0 - 3.5 and in interpreter choose python.
Note: "Quick Auto-Config" named "python" to the interpreter. If you did this part manually, you should know the exact name because you named it.
I wasted forever trying to get this to work as well..
I eventually found these steps (you don't need them all just part of my struggles shared).
in Python Shell:
import sys
print (sys.path)
Noticed NO PYGAME in path.
Eventually I GAVE UP on the .exe binaries and was told to use .WHL files and Python PIP to install. but was told NOT VALID wheel file. (frustrating).
what EVENTUALLY WORKED was to (in windows, but similar should work in other OS's).
run Command Prompt as Administrator (just to be sure) Maybe same in other OS's. you'd have to try.
from C:> i Changed Dir to my Python.exe (or the python program itself).
from my python directory in command prompt I typed the following (Like I would a Linux apt-get install command):
**
python.exe -m pip install pygame
**
Shortly after, there were hash marks ##### indicating a download was taking place (Linux type progress bar in shell).
in ECLIPSE without ever changing the Libraries folder to include PyGame folders I was able to run a sample Python PYGAME Script sample (I got a white screen but haven't gone further yet). I was just HAPPY to not have to see the trace back error message :)
now I am finished typing this to you I will be going to test it out further.
Just thought this would help someone :0)
I met such problem in Python 3.6 using LiClipse (which should be similar as Eclipse). It's solved by import pygame as
import pygame
from pygame.locals import *
Then add the pygame folder to Window>Preferences>PyDev>Interpreters>PyDev>Libraries, type in 'pygame' in the Forced BuiltIns tab at the same page, also right click the project, change Properties>PyDev-PYTHONPATH>Source from {proj_dir_name}/ to {proj_dir_name}/src
Maybe some above steps are not necessary. Anyway doing all aboves solves the problem in my case.