Compiling for OS X: ImportError: No module named ffi

After a long break, and the death of one laptop, I’m getting back into panda3d, but had some trouble compiling the latest CVS checkout for OS X against Python 2.6

I’ve noted a few threads mentioning this ImportError, but they date back a few years, so I wanted to find out what the latest might be.

Command I’m running:

python makepanda/makepanda.py --everything --use-python /usr/bin/python2.6 --osxtarget 10.6 --installer

Error I’m getting:

[ 92%] Generating 'pandac' tree 
Traceback (most recent call last):
  File "direct/src/ffi/jGenPyCode.py", line 74, in <module>
    from direct.ffi import DoGenPyCode
ImportError: No module named ffi

Helpful source thread: panda3d.org/forums/viewtopic … 501a777059

I see that the author of that other thread fixed his initial problem by fixing some paths, so I’m going to try to accomplish the same, but I wanted to seek some expert feedback in the meantime.

After some gross symlinks and hacking of the path, it barely gets past the import, only to fail with the following:

Traceback (most recent call last):
  File "direct/src/ffi/jGenPyCode.py", line 75, in <module>
    from direct.ffi import DoGenPyCode
  File "/Users/Akemi/Repositories/panda3d/direct/ffi/DoGenPyCode.py", line 11, in <module>
    from direct.ffi import FFIConstants
  File "/Users/Akemi/Repositories/panda3d/direct/src/ffi/FFIConstants.py", line 3, in <module>
    from direct.directnotify.DirectNotifyGlobal import *
  File "/Users/Akemi/Repositories/panda3d/direct/directnotify/DirectNotifyGlobal.py", line 3, in <module>
    import DirectNotify
  File "/Users/Akemi/Repositories/panda3d/direct/directnotify/DirectNotify.py", line 5, in <module>
    import Notifier
  File "/Users/Akemi/Repositories/panda3d/direct/directnotify/Notifier.py", line 6, in <module>
    from direct.showbase import PythonUtil
  File "/Users/Akemi/Repositories/panda3d/direct/showbase/PythonUtil.py", line 66, in <module>
    import direct.extensions_native.extension_native_helpers
  File "/Users/Akemi/Repositories/panda3d/direct/extensions_native/extension_native_helpers.py", line 81, in <module>
    Dtool_PreloadDLL("libpandaexpress")
  File "/Users/Akemi/Repositories/panda3d/direct/extensions_native/extension_native_helpers.py", line 79, in Dtool_PreloadDLL
    imp.load_dynamic(module, pathname)
ImportError: dlopen(/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib, 2): no suitable image found.  Did find:
	/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib: mach-o, but wrong architecture
	/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib: mach-o, but wrong architecture

I find this interesting, given that it is examining the items in my “built” directory, and deciding that what it built is not suitable. Have I missed something I should have specified in the compile options? I know 10.6 is the halfway x64 bastard child, so I wouldn’t be surprised-- I’m just not sure what to do about it :slight_smile:

Makepanda doesn’t really support building for x64 yet on OSX. So you’d need to modify makepanda and change the -arch flags to build for 64-bits.
Furthermore, the thirdparty packages that we ship are i386 and ppc only, so you’ll need to compile those for x86-64.

On a sidenote, you cannot pass an argument to --use-python. Instead, you should invoke makepanda with the version of Python that you intend to compile against.

As for the original problem - maybe something went wrong when it copied the “direct” tree to “built”. Try removing “built/direct” to force makepanda to re-copy it.

If you want to take the easy way, though, you could just use i386. The latest release, plus the daily buildbot releases should work on 10.6.

Good to know about not needing the path to python. In my situation, my “python” is in fact the same the one I tried to specify, so no harm done.

Really the only reason I’m trying to compile it myself is because of the Python 2.5 thing— I much much prefer 2.6. Is there an easier way that I can get to what I want?

You could just make an i386 build by invoking Python in 32-bits mode.

Well, that is what I’m attempting to do. I think I’m discovering that /usr/bin/python and /usr/bin/python2.6 are not in fact the same thing, as they are requiring separate methods for forcing the 32-bit architecture (environment variable versus Apple’s “arch -i386 /usr/bin/python2.6” command).

I removed my copy of the CVS repo and downloaded it again, to try from a clean copy, without my modifications. I was starting to get a weird problem with finding jpeglib.h, which is odd since I didn’t have that problem the first time I went through this.

I think I might have to defer this adventure until I go compile Python myself to make sure I’m not confused about what I’m using :slight_smile:

Thanks for the help thus far.

Well, I am fairly stumped.

Now running this command on makepanda.py:

arch -i386 python2.6 makepanda/makepanda.py --everything --no-jpeg --installer --osxtarget 10.6 --use-python

(I exclude libjpeg because my system is expressing trouble finding a 32-bit header file)

And I still get the architecture error mentioned before:

ImportError: dlopen(/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib, 2): no suitable image found.  Did find:
	/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib: mach-o, but wrong architecture
	/Users/Akemi/Repositories/panda3d/built/lib/libpandaexpress.dylib: mach-o, but wrong architecture

I have verified that python2.6 is running in 32-bit mode:

arch -i386 python2.6 -c "import sys; print sys.maxint"
2147483647

Any ideas? makepanda.py forces the -i386 architecture flag for OSX, so I’m not sure what else might be contributing to the mistaken architecture type. There were no warnings about individual files being in the wrong architecture before that message.

Try with these commands, they worked for me.

Well, I am using the “arch -i386” utility (which yields the correct sys.maxint value), but I suppose the art of being thorough demands that I try everything, despite the 35 minute wait until it reaches the error point in the compile process.

I’ve been avoiding the use of that permanent “Prefer-32-Bit” flag, since it isn’t my intention that I throw away any use of the 64-bit architecture. I think I’ll just set everything possible, and then undo it all if/when I get it to work.

EDIT: It doesn’t seem that the magic com.apple.versioner.python setting works anyway. It seems to have no impact on any version of Python on the system, of which I have many to test with :slight_smile:

Thanks for the info.

Maybe your build tree is borked? You can try removing the “built” directory to be sure.

I am having trouble getting panda3d to compile in osx 10.6 Using:

arch -i386 ppython makepanda/makepanda.py --everything --osxtarget 10.6 --installer

I also tried without the arch -i386

[ 92%] Generating ‘pandac’ tree
Importing code library: libpandaexpress
Found extensions for class: Ramfile
Found extensions for class: StreamReader
Found extensions for class: HTTPChannel
Importing code library: libpanda
Traceback (most recent call last):
File “direct/src/ffi/jGenPyCode.py”, line 94, in
DoGenPyCode.run()
File “/Users/warren/panda_hold/panda3d/built/direct/ffi/DoGenPyCode.py”, line 305, in run
generateNativeWrappers()
File “/Users/warren/panda_hold/panda3d/built/direct/ffi/DoGenPyCode.py”, line 258, in generateNativeWrappers
Dtool_PreloadDLL(moduleName)
File “/Users/warren/panda_hold/panda3d/built/direct/extensions_native/extension_native_helpers.py”, line 79, in Dtool_PreloadDLL
imp.load_dynamic(module, pathname)
ImportError: dlopen(/Users/warren/panda_hold/panda3d/built/lib/libpanda.dylib, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Users/warren/panda_hold/panda3d/built/lib/libpanda.dylib
Expected in: flat namespace
in /Users/warren/panda_hold/panda3d/built/lib/libpanda.dylib
Storing dependency cache.
Elapsed Time: 39 min 38 sec

I also have these at the beginning if it is of any use.

WARNING: Could not locate thirdparty package artoolkit, excluding from build
WARNING: Could not locate thirdparty package fcollada, excluding from build
WARNING: Could not locate thirdparty package fftw, excluding from build
WARNING: Could not locate thirdparty package fmodex, excluding from build
WARNING: Could not locate framework OpenGLES, excluding from build
WARNING: Could not locate thirdparty package gles2, excluding from build
WARNING: Could not locate thirdparty package egl, excluding from build
WARNING: Could not locate thirdparty package osmesa, excluding from build
WARNING: Could not locate pkg-config package gtk±2.0, excluding from build
WARNING: Could not locate thirdparty package opencv, excluding from build
WARNING: Could not locate thirdparty package squish, excluding from build
WARNING: Could not locate thirdparty package tiff, excluding from build
WARNING: Could not locate thirdparty package vrpn, excluding from build

Any ideas? Thanks

Looks like you’re missing the i386 version of the JPEG lib? I had a similar problem, which is why I skipped over it by adding the extra --no-jpeg flag to the command.

I’m curious to know what happens when you ignore the whole JPEG thing, if that is in fact what’s going on here.

I think i got past the jpeg issue by using jpegsrc.v7.tar.gz

CC=”gcc -arch i386" ./configure –enable-shared –enable-static
sudo arch -i386 make
sudo arch -i386 make install

Of course many other things are now failing, but I will try the same strategy with these other packages.

If this fails, you could always just try compiling against the 10.5 SDK instead.

I actually successfully build Panda against Python 2.6 against the 10.4 SDK (although I compile it on Leopard).

Well i managed to compile with

arch -i386 ppython makepanda/makepanda.py --everything --osxtarget 10.6 --installer --no-ffmpeg --no-ode

And it completed, but cannot load any of the sample programs i tried. I get:

:audio(error): load_dso(libp3fmod_audio.so) failed, will use NullAudioManager
:audio(error): No error.
Bus error

The window is white, then closes.

Any idea which package this could be? OpenAL, FMOD?

What packages did you install before compiling?

Compiling with --osxtarget 10.5 got rid of the audio errors, but the bus error remains, and I cannot run anything.

It is really too bad it is this hard to compile the source on osx. I will gladly document the process in detail if I can get a better idea of what might be causing this, and what packages are required.

I’d like to see a gdb backtrace of the bus error. You can also try switching to OpenAL by putting this in the /Developer/Panda3D/etc/Config.prc file:

audio-library-name p3openal_audio

That is good to know about that runtime config. Unfortunately it gave me a new error when trying to run the roaming ralph demo:

:audio(error): load_dso(libp3openal_audio.so) failed, will use NullAudioManager
:audio(error): dlopen(/Developer/Panda3D/lib/libp3openal_audio.dylib, 10): Symbol not found: _alBufferData
Referenced from: /Developer/Panda3D/lib/libp3openal_audio.dylib
Expected in: flat namespace
in /Developer/Panda3D/lib/libp3openal_audio.dylib
Bus error

which is strange considering:

grep -irn _alBufferData *
Binary file lib/libp3openal_audio.dylib matches

I installed openal from the dmg. Maybe ill try from source.

I ran it with gdb… here a bt, but not sure if this is helpful.

Reading symbols for shared libraries . done
:audio(error): load_dso(libp3openal_audio.so) failed, will use NullAudioManager
:audio(error): dlopen(/Developer/Panda3D/lib/libp3openal_audio.dylib, 10): Symbol not found: _alBufferData
Referenced from: /Developer/Panda3D/lib/libp3openal_audio.dylib
Expected in: flat namespace
in /Developer/Panda3D/lib/libp3openal_audio.dylib
Reading symbols for shared libraries . done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000004
0x00099f8e in PySys_GetObject ()
(gdb) bt
#0 0x00099f8e in PySys_GetObject ()
#1 0x004588de in ExecutionEnvironment::ns_get_environment_variable ()
#2 0x0045904a in ExecutionEnvironment::expand_string ()
#3 0x004c6be5 in ConfigVariableSearchPath::reload_search_path ()
#4 0x01610afc in Loader::load_file ()
#5 0x01864a00 in Dtool_Loader_load_sync_1218 ()
#6 0x0007ad1f in PyEval_EvalFrameEx ()
#7 0x0007caaa in PyEval_EvalCodeEx ()
#8 0x0007af76 in PyEval_EvalFrameEx ()
#9 0x0007caaa in PyEval_EvalCodeEx ()
#10 0x00027472 in PyClassMethod_New ()
#11 0x0000c268 in PyObject_Call ()
#12 0x00015d77 in PyClass_New ()
#13 0x0000c268 in PyObject_Call ()
#14 0x000760e0 in PyEval_CallObjectWithKeywords ()
#15 0x0001562f in PyInstance_New ()
#16 0x0000c268 in PyObject_Call ()
#17 0x0007c319 in PyEval_EvalFrameEx ()
#18 0x0007caaa in PyEval_EvalCodeEx ()
#19 0x0007cb4f in PyEval_EvalCode ()
#20 0x00094a03 in Py_CompileString ()
#21 0x00094aaf in PyRun_FileExFlags ()
#22 0x00095f34 in PyRun_SimpleFileExFlags ()
#23 0x000a1f2c in Py_Main ()
#24 0x00001eb5 in ?? ()
(gdb)