Loader error when using setuptools – 'couldn't load file' .... 'not found on the model path'

If I use setuptools to bundle a small program that just opens a grey window and doesn’t load anything, the distributable produced works fine.

However, if I create a program that loads a model (like the tutorial in the Panda3D manual), setuptools still produces an app, but it doesn’t open.

My program (02_grassy_scene) is this:

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        # Load the environment model
        self.scene = self.loader.loadModel("models/environment")

        # Reparent the model to render
        self.scene.reparentTo(self.render)

        # Apply scale and position transforms on the model
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)


app = MyApp()
app.run()

My setup.py is this:

from setuptools import setup

setup( # Parameters of the program go in here
    name = "Grassy Scene",
    options = {
        "build_apps" : { # Build options go in here
            "include_patterns" : ["**/*.egg"],
            "gui_apps" : {"Grassy Scene" : "02_grass_scene.py"},
            "plugins" : ["pandagl"],
        }
    }
)

And this is the error I get when I try to run the program:

:loader(error): Couldn't load file models/environment.egg: not found on model path (currently: "/Volumes/iMac and MBP Files/Programming/Python/Panda3D/Tutorials from the Manual/02/build/macosx_10_6_x86_64/Grassy Scene.app/Contents/MacOS/../Resources:/..:/../models")
Traceback (most recent call last):
  File "02_grass_scene.py", line 18, in <module>
    app = MyApp()
  File "02_grass_scene.py", line 8, in __init__
    self.scene = self.loader.loadModel("models/environment")
  File "/Volumes/iMac and MBP Files/Programming/Python/Panda3D/Tutorials from the Manual/02/build/__whl_cache__/panda3d-1.10.4.1+opt-cp37-cp37m-macosx_10_6_x86_64.whl/direct/showbase/Loader.py", line 286, in loadModel
OSError: Could not load model file(s): ['models/environment']

I have a models directory in the same folder as 02_grassy_scene.py and the environment.egg.pz model is in that directory. When I run the program normally (without setuptools), it works fine and is able to find the model in the models folder. In fact, it even shows up in getModelPaths().

What could be going wrong in the meantime?

Also, in the setup.py file, in the include-patterns line, where is **/*.egg?

Your model is called environment.egg.pz but you have an include pattern of *.egg. You should add a pattern like **/*.egg.pz or punzip the model.

I tried the first option, changing the pattern to **/*.egg.pz and got this error:

:loader(error): Extension of file models/environment.egg is unrecognized; cannot load.
Currently known scene file types are:
  Bam                             .bam
:loader(error): Couldn't load file models/environment.egg: all matching files on model path invalid (the model path is currently: "/Volumes/iMac and MBP Files/Programming/Python/Panda3D/Tutorials from the Manual/02/build/macosx_10_6_x86_64/Grassy Scene.app/Contents/MacOS/../Resources:/..:/../models")
Traceback (most recent call last):
  File "02_grass_scene.py", line 19, in <module>
    app = MyApp()
  File "02_grass_scene.py", line 9, in __init__
    self.scene = self.loader.loadModel("models/environment")
  File "/Volumes/iMac and MBP Files/Programming/Python/Panda3D/Tutorials from the Manual/02/build/__whl_cache__/panda3d-1.10.4.1+opt-cp37-cp37m-macosx_10_6_x86_64.whl/direct/showbase/Loader.py", line 286, in loadModel
OSError: Could not load model file(s): ['models/environment']

So that didn’t work.

But I tried the second option, I ran /Developer/Tools/Panda3D/punzip environment.egg.pz and it worked! The program opened on my Mac! :grin:

But it’s not quite working on Windows and Linux. The program opens and stays open, but there is a blank white screen, the models aren’t loading, even though they are definitely in the right place.

Before using setuptools, I have the .egg files (which have been punzipped), but after using setuptools, they have become .egg.bam files.

I wonder if that’s what’s stopping the models from loading.
But I’m not sure why it would, because the .egg.bam files work in MacOS.

Is there command-line output? Or, if you have enabled logging, content in the log file?

Ah yes, I forgot to check.

On Linux:

Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
pci id for fd 5: 80ee:beef, driver (null)
OpenGL Warning: glFlushVertexArrayRangeNV not found in mesa table
OpenGL Warning: glVertexArrayRangeNV not found in mesa table
OpenGL Warning: glCombinerInputNV not found in mesa table
OpenGL Warning: glCombinerOutputNV not found in mesa table
OpenGL Warning: glCombinerParameterfNV not found in mesa table
OpenGL Warning: glCombinerParameterfvNV not found in mesa table
OpenGL Warning: glCombinerParameteriNV not found in mesa table
OpenGL Warning: glCombinerParameterivNV not found in mesa table
OpenGL Warning: glFinalCombinerInputNV not found in mesa table
OpenGL Warning: glGetCombinerInputParameterfvNV not found in mesa table
OpenGL Warning: glGetCombinerInputParameterivNV not found in mesa table
OpenGL Warning: glGetCombinerOutputParameterfvNV not found in mesa table
OpenGL Warning: glGetCombinerOutputParameterivNV not found in mesa table
OpenGL Warning: glGetFinalCombinerInputParameterfvNV not found in mesa table
OpenGL Warning: glGetFinalCombinerInputParameterivNV not found in mesa table
OpenGL Warning: glDeleteFencesNV not found in mesa table
OpenGL Warning: glFinishFenceNV not found in mesa table
OpenGL Warning: glGenFencesNV not found in mesa table
OpenGL Warning: glGetFenceivNV not found in mesa table
OpenGL Warning: glIsFenceNV not found in mesa table
OpenGL Warning: glSetFenceNV not found in mesa table
OpenGL Warning: glTestFenceNV not found in mesa table
libGL error: core dri or dri2 extension not found
libGL error: failed to load driver: vboxvideo
OpenGL Warning: glXChooseFBConfig returning NULL, due to attrib=0x6, next=0xffffffff
:display:glxdisplay(warning): No suitable FBConfig contexts available; using XVisual only.
depth_bits=24 color_bits=24 red_bits=8 green_bits=8 blue_bits=8 alpha_bits=8 stencil_bits=8 accum_bits=64 back_buffers=1 stereo force_hardware 
:display:gsg:glgsg(warning): Occlusion queries advertised as supported by OpenGL runtime, but could not get pointers to extension functions.
:device(warning): /dev/input/event5 is not readable, some features will be unavailable.
:device(warning): /dev/input/event6 is not readable, some features will be unavailable.
:audio(error):   load_dso(libp3openal_audio.so) failed, will use NullAudioManager
:audio(error):     No error.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-treetrunk.jpg
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-treetrunk.jpg" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-tree1.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-tree1.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-ground.jpg
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-ground.jpg" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-tree2.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-tree2.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-rock1.jpg
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-rock1.jpg" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-rock2.jpg
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-rock2.jpg" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-bamboo.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-bamboo.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-reeds.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-reeds.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-groundcover1.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-groundcover1.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-mountain1.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-mountain1.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-mountain2.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-mountain2.png" does not exist.
:gobj(error): Texture::read() - couldn't read: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-cylinder.png
:gobj(error): Texture "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/panda3d/models/maps/envir-cylinder.png" does not exist.

I can normally run OpenGL programs despite all the OpenGL warnings and errors. But the :gobj errors are new and I guess those are the issue.

I figured it out!

All I had to do was make copies of the models and textures within models and maps folders within the main.py directory. It all makes sense now, I understand how the model-paths work and how to use them properly to make a cross-platform app. I’m so glad it finally works, thank you @rdb for your help!