loader.loadModel file paths

I am having a serious (but no doubt novice type) problem with loading a model (.obj) file using a full directory path.

this works ( FROM THE PROGRAMS DIRECTORY but this is not what I want)

self.environ = self.loader.loadModel(‘\ObjFiles\test.obj’

this doesn’t
self.environ = self.loader.loadModel(
neither does this
(I thought the IDE splitting the line might be at fault) so …

oFile = ‘C:\Users\richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj’

self.environ = self.loader.loadModel(oFile)

same error message

OSError: Could not load model file(s): [‘C:\Users\richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj’]

oFile = ‘C:\Users\richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj’


Having pulled my hair out trying different combinations of // \ '\c 'C:\ etc I tried a simple file read (in same directory…

oFile = ‘C:\Users\richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj’

def main():
f = open(oFile, “r”)
if name == ‘main’:

works fine … HELP HELP PLEASE…
[Apologies if this is not in the forum’s expected style but have no idea how to drop bits of code etc…

thanks for any help - Richard

I think that the problem may be that Panda uses Linux-style file-names–so forward-slashes and no colons for drive-names. The format would thus be something like this, I believe:


(I’m not sure of whether the “c” should be capitalised, offhand; if lower-case doesn’t work, try upper-case.)

I am new to panda3d, but if what Thaumaturge says doesn’t work, you should probably try:

path = str(Path.home() / 'Documents' / 'Python' / 'Panda' / 'FirstPersonCamera' / 'ObjFiles' / 'test.obj')
self.environ = self.loader.loadModel(path)

Also, to format, do ``` at the beginning and end of the code. In addition, you can use html along with the buttons above the editing box.

Nope -

Sorry but neither suggestions work

I have now tried with import os

cwd = os.getcwd()

subd = ‘\ObjFiles\’
objFile = ‘test.obj’

  • interesting - I copied text file in that had double slashes - it has posted as single slashes, I have just gone into edit and the double slashes are there but it only displays single slashes - wtbh?
    oFile = cwd+subd+objFile - abject failure

interesting thing
if i print(cwd) I get C:\Users\Richard\Documents\Python\Panda\FirstPersonCamera
if I print ofile C:\Users\Richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj

so something is changing the \ to \ ???
why is the error reading
OSError: Could not load model file(s): [‘C:\Users\Richard\Documents\Python\Panda\FirstPersonCamera\ObjFiles\test.obj’]
again all(double slashes) the editor is only displaying singles. ///

is it that the path is too long for loader to cope with ?

I’m not sure of whether there’s a maximum length, but I am very confident that a Windows-style path-format won’t work in Panda’s model-loader. I’d recommend switching to the Linux-style path-format, and experimenting from there to find the problem. (If no-one else chimes in with a more-specific solution, at least.)

(Other modules like “os” may have behave differently–hence at least some of the differing results that you’re seeing.)

I am not at all sure of what the forum-software is doing with your double-slashes; some may be being treated as escape characters, perhaps. ^^;

Make sure you did pip install pathlib in the terminal and from pathlib import Path at the top of your script. Other than that, I cannot help you. I’d suggest, though, that you just make the path something more simple like:
Also, make sure that you can import files into programs with other libraries - basic ones that play a sound or something. Then, I reccomend using str('hi' / 'im' / 'me.test'), instead of using 'hi/im/me.test'

once again, thanks for the advice & effort in replyng - for now will stick with the sub directory approach … too much time spent on full paths !!
Again thanks - Richard

1 Like


If you use pathlib, you shouldn’t use str() to convert it to a string.

However, you don’t need to use pathlib. You should use UNIX-style paths, with forward slashes, like /c/Users/richard/Documents/...

Of course, your game will not work on anyone else’s computer this way (unless they are also named “richard” and have the files in the same location). So relative paths are the way to go.

You can convert a Windows-style path to a UNIX-style path using Filename.fromOsSpecific("C:\\Users\\richard\\Documents\\..") note the use of double backslashes to prevent Python from interpreting it as an escape sequence.

1 Like

Greetings, and thanks for the responce, I have already taken the advice and resorted to using a ‘local’ subdirectory but, just to check out your solution;

f = Filename.fromOsSpecific(‘C:\Users\richard\Documents\Python\Panda\FirstPersonCamera\models\G.obj’)

response ; SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

from the manual;

staticfromOsSpecific(os_specific: str, type: Type)→ Filename
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).

Use this function to create a Filename from an externally-given filename string. Use toOsSpecific() again later to reconvert it back to the local operating system’s conventions.

This function will do the right thing even if the filename is partially local conventions and partially Panda conventions; e.g. some backslashes and some forward slashes.

sorry to be ‘long winded’ but this whole exercise is precisely an exercise in an attempt for myself to understand Panda3D & Python.

From my understanding of the manual i should get a useable path to the file - I don’t.

All of this came about due to something else I do not understand.
I kept editing the obj file but nothing changed in the ‘scene’ .
P3D loads the bam image without looking at the ‘real’ file; I understand why - much quicker if no changes but as far as I can make out it just loads the dump with no regard to the physical file which may have (and in my case always has )changed
Question, is this a result of using obj files rather than egg or is it the norm; if so is there a way to switch it off, i.e. force the program to use the physical file rather than the RAM dump ?
I have resorted to deleting the bam files using a batch file.
echo on
dir C:\Users\richa\AppData\Local\Panda3D-1.10 (took me a lot of searching to find this directory)

del C:\Users\richa\AppData\Local\Panda3D-1.10*.*
dir C:\Users\richa\AppData\Local\Panda3D-1.10

echo 0ff

wonders of wonders changes are now shown AND with the addition of

loadPrcFileData(“”, “model-path $MAIN_DIR/models”) (ttok a lot of searching etc…)

all texture files load and render correctly i.e. correspond to the obj file dumped into 3D Viewer.

So, to summerise, problem fixed, don’t believe the manual (I should know this from working on my car), ask the community (with grateful THANKS) and persevere

(marked as solved rather than given up !) Richard

from direct.showbase.ShowBase import ShowBase
from panda3d.core import Filename

class MyApp(ShowBase):

    def __init__(self):

        f = Filename.fromOsSpecific('C:\\Users\\richard\\Documents\\Python\\Panda\\FirstPersonCamera\\models\\G.obj')

app = MyApp()

out: /c/Users/richard/Documents/Python/Panda/FirstPersonCamera/models/G.obj

1 Like
from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):

        scene = loader.loadModel("models/environment", noCache = True)

app = MyApp()

This can be disabled by passing this flag. It does not depend on the type of file used, as far as I remember, if you load a bam file, it will also be cached.


Thank you very much indeed - works like a charm!
2 Files are still created index_name and index???.boo but they don’t affect the program

EXCELLENT - thanks again

It just goes to show how much I’ve got to learn


The index with the associated model is also cached, the goal is not to load the object twice.

1 Like