Error Importing Panda3D in OS X

I’m using OS X El Capitan and have been unable to setup panda3D on my Macbook Pro.

Running this line from the examples, or the hello world tutorial:

from direct.showbase.ShowBase import ShowBase

Makes python 2.7.10 quit unexpectedly, and crashes.

My Python path contains ‘/Developer/Panda3D’, and I have tried adding ‘/Developer/Panda3D/bin’ to it as well to see if that helps, but it did not.

I started playing around with it to try and trace back the error, and I found that these commands do not cause errors:

>>> from direct import showbase
>>> import panda3d
>>> from panda3d import *

These commands cause python to crash

>>> from direct.showbase import ShowBase
>>> from direct.showbase.ShowBase import *
>>> from panda3d import core
>>> from panda3d import physics
>>> from panda3d import direct

Importing something that clearly does not exist however, such as when I tried:

from panda3d import fnajkpng

Does not make it crash like that, just prints the error, so it appears to be finding the files, but failing to use them.

So it seems to crash whenever it tries to import anything from ‘Panda3D/panda3d’. The files in there are all modules with a .so extension that I am unfamiliar with, but after googling it I saw something someone posted about how you need to import a .so and it isn’t working you can try including something like from the same directory as the .so:

def __bootstrap__():
   global __bootstrap__, __loader__, __file__
   import sys, pkg_resources, imp
   __file__ = pkg_resources.resource_filename(__name__,'direct.so') #or whatever the filename
   __loader__ = None; del __bootstrap__, __loader__
   imp.load_dynamic(__name__,__file__)
__bootstrap__()

This also crashes, and when run from terminal gives the error “ImportError: dynamic module does not define init function (init__main__)”. Googling that found nothing that I could directly make use of, but appeared to indicate that this error is associated with python modules written in c/c++ that are not implemented correctly to be used as a python module.

If someone could please point me in the right direction as to how to solve this, that would be great. Probably half the things I wrote down in here aren’t useful, but I included everything I have found out. I also checked basic stuff like, is my default python the same as that used in IDLE, and I believe it is. Thank you for your help.

My bad, I did not realize I had to use ppython instead of python. Looking back I found this in the tutorials, but I think it could have been emphasized more, because I personally just skimmed over the terminal commands stuff because I usually am not running my programs from terminal, (since IDLE, Sublime, and all of those make it faster to run it without leaving the window). Is there any plans to support the standard python instead of needing to use ppython in the future? It seems like it could add a lot of hassle if you are using other libraries as well for something, and need to set up everything twice.

Panda works out of the box with Apple’s standard copy of Python, so there is no need to use ppython. In fact, ppython is just a link to Apple’s standard copy of Python.

What I’m guessing you did is install a custom version of Python 2.7 alongside the version of Python 2.7 that is already on your system, one that is incompatible with Panda’s build.

Hmm, that could be, thanks. I think I setup python with homebrew. I ended up just making a launcher for my application:

import subprocess
command = "ppython name_of_main_file.py"
output = subprocess.check_output(['bash','-c', command])
print output

There will be a fix for this in the upcoming 1.9.3 release of Panda.

thanks for reply . I solved this problem. :slight_smile:

slotonline