Import error on packages from p3d

I’m having some trouble importing packages, like pygame, when running my program after converting it to a p3d using pack3d. This sample code demonstrates the problem:

#!/usr/bin/env python
# these work
import sqlite3
import numpy

# these don't
import pygame
import httplib2
import PIL

def main(a = None):
  print 'Hello, World!'

if __name__ == '__main__':
  main()

If I run the program normally it works:

$ ./test.py 
Hello, World!

But if I pack it up and run the p3d then some of the imports fail:

$ panda3d packp3d.p3d -m test.py -o test.p3d -r numpy -r pil -r pygame -r sqlite -r httplib2
:AppRunner: Total Panda3D disk space used: 191 MB
:AppRunner: Configured max usage is: 2048 MB
Rejecting package httplib2, version "cmu_1.7": depends on panda3d, version "cmu_1.7" instead of version "cmu_1.8"
:Packager(warning): No such file: /tmp/p3d_info.xml
Generating test.p3d


$ panda3d test.p3d 
:AppRunner: Total Panda3D disk space used: 191 MB
:AppRunner: Configured max usage is: 2048 MB
Traceback (most recent call last):
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/showbase/Messenger.py", line 424, in __taskChainDispatch
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/showbase/Messenger.py", line 482, in __dispatch
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/p3d/AppRunner.py", line 748, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "/tmp/test.py", line 7, in <module>
    import pygame
  File "VFSImporter", line 446, in load_module
ImportError
:task(error): Exception occurred in PythonTask Messenger-default
Traceback (most recent call last):
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/p3d/AppRunner.py", line 638, in run
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/task/Task.py", line 502, in run
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/task/Task.py", line 460, in step
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/showbase/Messenger.py", line 424, in __taskChainDispatch
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/showbase/Messenger.py", line 482, in __dispatch
  File "/home/buildbot/slave/release_rtdist_linux_i386/build/panda3d/built_cmu/direct/p3d/AppRunner.py", line 748, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "/tmp/test.py", line 7, in <module>
    import pygame
  File "VFSImporter", line 446, in load_module
ImportError
Successfully joined thread: 0
Failure on startup.

I’m a newb here so I’m sure I’m just missing something important, but I’ve scoured the manual for an hour and can’t see what I’m doing wrong. This is panda 1.8 on 32-bit linux mint 14, python 2.7.

Can anyone help?

If you want extra modules included in in your p3d, you need to add them somehow.

You can add them by including another package that contains them:
panda3d.org/manual/index.php … g_packages
(you can also make your own such packages)

Or you can add those libraries directly to your p3d file.

Be sure to checkout the “multify” tool for unpacking your p3d to see whats in it to help debug packaging issues.

I thought that’s exactly what I was doing by including all those -r switches to the pack3d command, like it says in the page you linked.

If I clear my hosts cache then run my p3d file, it goes and downloads the packages that I specified, so it must know that I want them, but they’re not accessible from the program at run-time. :confused:

Thanks for the tip about multify. My p3d file contains the compile python object and the info xml:

<?xml version="1.0" encoding="utf-8" ?>
<package name="test" main_module="test">
    <requires name="panda3d" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <requires name="numpy" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <requires name="pil" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <requires name="pygame" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <requires name="sqlite" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <requires name="httplib2" version="cmu_1.8" host="https://runtime.panda3d.org/" seq="2" />
    <host url="https://runtime.panda3d.org/" download_url="http://runtime.panda3d.org/" />
</package>

That looks right to me, and all those packages do exist at runtime.panda3d.org/

Perhaps those packages are broken somehow. You can try unpacking one of the non-working packages with multify, and seeing if it works.

Anyway, my current guess would be simple that those packages don’t work on your OS for some reason, and thats a bug. If you can debug it, awesome. If you can test on some other OSs, great, but either way, perhaps its time to file a bug?

This looks worrisome to me:

Rejecting package httplib2, version "cmu_1.7": depends on panda3d, version "cmu_1.7" instead of version "cmu_1.8" 

What version of packp3d did you build it with? The one built against 1.7 or 1.8?

I’m definitely using the pack3d for 1.8, tripled check it and even redownloaded it from runtime.panda3d.org.

I managed to trace through the VFSImporter, which was actually kind of helpful. In the case of pygame and httplib2 the actual ImportError is being silenced at line 153 when it tries to exec the code into a new module.

For pygame the real error is:
ImportError:‘/usr/lib/i386-linux-gnu/libsndfile.so.1: undefined symbol: vorbis_version_string’

And for httplib2 the real error is:
ImportError:‘No module named aliases’

I’m still not certain if the fault lies with me or with the panda tools, but this is a lot more informative than what I got before!