Python + PyGame + SDL + NumPy + Eclipse + PyDev

Discussion in 'Mac Programming' started by wrldwzrd89, Nov 22, 2009.

  1. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #1
    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.
     
  2. rowsdower macrumors 6502

    Joined:
    Jun 2, 2009
    #2
    Did you install a different version of Python? Maybe Eclipse is picking up the Python that came with the system.
     
  3. wrldwzrd89 thread starter macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #3
    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.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Where does Python look for imports? Some kind of list or path?

    Write a Python program that outputs the runtime list or path.
     
  5. wrldwzrd89 thread starter macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #5
    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
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    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?
     
  7. wrldwzrd89 thread starter macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #7
    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.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    How would you prove, or at least provide evidence for, these suppositions?


    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.
     
  9. wrldwzrd89 thread starter macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #9
    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:
     
  10. sylvanhistorian macrumors newbie

    Joined:
    Nov 22, 2009
    #10
    I have the same error

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

Share This Page