Mac Python + PyGame + SDL + NumPy + Eclipse + PyDev

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,107
75
Solon, OH
Hey all. I'm using Python 2.6.4, Eclipse 3.5, PyGame 1.9.1, SDL 1.2.14, NumPy 1.3.0, and PyDev 1.5.0 to develop a game on the Mac. However, I have run into an odd problem.

If I try these simple lines of test code in the Terminal, after starting the Python interpreter:
Code:
import numpy
test = numpy.zeros((2, 3), numpy.int16)
type(test)
I get back numpy.ndarray as the type, as expected.

Trying the same lines in Eclipse gives me 2 error messages:
Code:
undefined variable from import: zeros
undefined variable from import: int16
Something's obviously screwy here in Eclipse, since it works just fine at the command line. I cannot figure out what, though.
 

rowsdower

macrumors 6502
Jun 2, 2009
270
1
Did you install a different version of Python? Maybe Eclipse is picking up the Python that came with the system.
 
Comment

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,107
75
Solon, OH
Did you install a different version of Python? Maybe Eclipse is picking up the Python that came with the system.
Yes, I did. I installed the Python 2.6.4 package from Python.org. However, I have PyDev set to use the Python 2.6.4 I installed, and not the system Python.
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,671
4,942
vertical
Where does Python look for imports? Some kind of list or path?

Write a Python program that outputs the runtime list or path.
 
Comment

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,107
75
Solon, OH
Where does Python look for imports? Some kind of list or path?

Write a Python program that outputs the runtime list or path.
I found a program that does exactly that, here: http://www.daniweb.com/forums/thread58790.html

Here is the source code:

Code:
# show the system path for Python --> PYTHONPATH
import sys
print "These are the directories Python looks into for modules and source files:"
for folder in sys.path:
	print folder
print "-"*30 # print 30 dashes
print "This would be your present working folder/directory:"
print sys.path[0]
Here is what it outputs:
Code:
These are the directories Python looks into for modules and source files:
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode
/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6
------------------------------
This would be your present working folder/directory:
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src
For clarity, the output from the Terminal when running the same program:
Code:
Eric-Ahnells-iMac:~ wrldwzrd89$ cd /Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src 
Eric-Ahnells-iMac:src wrldwzrd89$ python pythonpath.py
These are the directories Python looks into for modules and source files:
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode
/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6
------------------------------
This would be your present working folder/directory:
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/Eclipse/Python/PythonPath/src
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,671
4,942
vertical
In which of those locations is the NumPy module?

Does NumPy depend on other modules? Is there more than one version of the dependent module in sys.path, making the path's order significant?

What happens if you run python from Eclipse with the same sys.path as Terminal uses?

http://docs.python.org/library/sys.html#sys.path

Is python 64-bit? If so, might Terminal be running one arch and Eclipse another?
 
Comment

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,107
75
Solon, OH
In which of those locations is the NumPy module?

Does NumPy depend on other modules? Is there more than one version of the dependent module in sys.path, making the path's order significant?

What happens if you run python from Eclipse with the same sys.path as Terminal uses?

http://docs.python.org/library/sys.html#sys.path

Is python 64-bit? If so, might Terminal be running one arch and Eclipse another?
NumPy is in a subfolder of /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages, just like most Python extensions. As far as I know, NumPy does NOT have any inter-module dependencies. There aren't any other versions of NumPy that I can find in the path. Python should be 32-bit, since I'm using the Python from python.org, not the system Python (I ran the update shell script to tell bash to use the Python I installed instead of the system one). NumPy only exists inside the Python I installed, so that can't be the problem. Eclipse won't let me change the order of PYTHONPATH entries.
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,671
4,942
vertical
As far as I know, NumPy does NOT have any inter-module dependencies. ... Python should be 32-bit, ...
How would you prove, or at least provide evidence for, these suppositions?


Eclipse won't let me change the order of PYTHONPATH entries.
Google keywords: eclipse python path

Top search result: http://plone.org/documentation/tuto...with-eclipse/setting-up-pythonpath-in-eclipse


Or what about appending or inserting values into sys.path?


If you can't make Eclipse work like Terminal, try making Terminal fail like Eclipse. Set the env-vars etc. so it exactly matches Eclipse, and see if it fails the same way. If it still works, then sys.path isn't the cause. If it fails, then you have a starting point.

As last resort, you may want to rethink what you're using to write this game.
 
Comment

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,107
75
Solon, OH
Well, this is most strange. I just tried running the test code in Eclipse, ignoring the "errors" it reports, and... it runs just fine. The python interpreter likes my program... so I guess Eclipse is just confused. :confused:
 
Comment

sylvanhistorian

macrumors newbie
Nov 22, 2009
1
0
I have the same error

Your problem is not unique; I have exactly the same problem with numpy on eclipse.
 
Comment

Similar threads

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.