View Full Version : Python + PyGame + SDL + NumPy + Eclipse + PyDev
wrldwzrd89
Nov 22, 2009, 10:19 AM
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:
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:
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
Nov 22, 2009, 10:58 AM
Did you install a different version of Python? Maybe Eclipse is picking up the Python that came with the system.
wrldwzrd89
Nov 22, 2009, 11:14 AM
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.
chown33
Nov 22, 2009, 01:13 PM
Where does Python look for imports? Some kind of list or path?
Write a Python program that outputs the runtime list or path.
wrldwzrd89
Nov 22, 2009, 02:17 PM
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:
# 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:
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:
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
chown33
Nov 22, 2009, 07:00 PM
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?
wrldwzrd89
Nov 22, 2009, 07:42 PM
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.
chown33
Nov 22, 2009, 11:45 PM
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/tutorial/developing-plone-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.
wrldwzrd89
Nov 25, 2009, 06:23 PM
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:
sylvanhistorian
Dec 4, 2009, 07:58 PM
Your problem is not unique; I have exactly the same problem with numpy on eclipse.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.