p3d file and this...

Why does this line of code cause my generated p3d file to close immediately:

wallpaperPath = Filename.fromOsSpecific("C:\Users\\something.dat")

You can get a better idea if you run your p3d file from the command line. Any errors you get will be printed out there.

packp3d -o example.p3d -d example -r morepy
C:\Users\User\Desktop>panda3d example.p3d
:AppRunner: Total Panda3D disk space used: 310 MB
:AppRunner: Configured max usage is: 2048 MB
DirectStart: Starting the game.
:audio: NullAudioManager
:audio: NullAudioManager
:ShowBase: __dev__ == False
:display: loading display module: libpandagl.dll
:display: loading display module: libpandadx9.dll
:display: loading display module: libpandadx8.dll
:display: loading display module: libp3tinydisplay.dll
Known pipe types:
  wglGraphicsPipe
  wdxGraphicsPipe9
  wdxGraphicsPipe8
  TinyWinGraphicsPipe
  TinyOffscreenGraphicsPipe
(all display modules loaded.)
:display:windisplay: OS version: 6.1.2.7600
:display:windisplay:
:display:windisplay: max Mhz 2267000000, current Mhz 2267000000
:ShowBase: Default graphics pipe is wglGraphicsPipe (OpenGL).
:display: Created output of type wglGraphicsWindow
:display: Unable to set window properties: !undecorated !fixed_size
:ShowBase: Successfully opened window of type wglGraphicsWindow (OpenGL)
Traceback (most recent call last):
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 424, in __taskChainDispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 482, in __dispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\Ap
pRunner.py", line 748, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "C:\Users\User\Desktop\example\main.py", line 27, in <module>
    username = getpass.getuser()
  File "c:\python27\lib\getpass.py", line 157, in getuser
ImportError: No module named pwd
:task(error): Exception occurred in PythonTask Messenger-default
Traceback (most recent call last):
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\Ap
pRunner.py", line 638, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\T
ask.py", line 502, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\T
ask.py", line 460, in step
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 424, in __taskChainDispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 482, in __dispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\Ap
pRunner.py", line 748, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "C:\Users\User\Desktop\example\main.py", line 27, in <module>
    username = getpass.getuser()
  File "c:\python27\lib\getpass.py", line 157, in getuser
ImportError: No module named pwd
:TaskManager: TaskManager.destroy()
:display: Closing wglGraphicsWindow
Failure on startup.

BTW, there’s no “c:\python27”, I don’t know where the heck it’s getting that.

Try escaping both slashes?

wallpaperPath = Filename.fromOsSpecific("C:\\Users\\something.dat")

Read the error message, it’s a different issue.

This is a bug/limitation of the Python getuser() API. On Windows, it tries to get the username by using the environment variables; in the case of the runtime, these aren’t (apparently) available, so it falls back to trying the “pwd” module. However, the “pwd” module is not available on Windows, so it fails at that point.

There’s not much that can be done on the Panda side to fix this, except perhaps pass through the appropriate environment variables so that getuser() can work correctly.

Is there a specific reason why you need to use getuser()? Panda provides many variables that you can use in filenames for storing user-specific application-data, such as $USER_APPDATA (aka Filename.getUserAppdataDirectory()).

Yeah, I need to know the current username.
How is this not a Panda issue? It only shows up when running inside a p3d file.

It’s a Python bug that is revealed in the way Panda manages the environment variables in the p3d environment.

You can change this environment management by adding “-c keep_user_env=1”, which will tell Panda you want it to keep all of the user’s environment variables around. This won’t work if you want to run the p3d file in a web page, though, where the environment variables aren’t available period, for security reasons.

David

What do you need the username for? Perhaps we can help you find an alternative solution?

I want it displayed.

In that case, you’ll probably want the user’s display name on Windows. This might help:

sjohannes.wordpress.com/2010/06/ … ng-ctypes/