import DirectStart problems

I’m having a weird problem with import direct.directbase.DirectStart. I’m unable to run the Panda3d examples and even my own very simple programs won’t run. I get this when I try to run them: “ImportError: cannot import name DirectNotifyGlobal.” I have installed and uninstalled Panda a few times and I wonder if this has anything to do with it. Earlier the programs did work but not on this nor the previous install. I tried searching my hard drive for ppython and the search found the exe in Panda’s bin folder and these:, both in the folder C:\WINDOWS\Prefetch (I’m using Windows XP). I don’t know what these are and I don’t know if they have anything to do with the problem.

Any help is appreciated.

I reinstalled Panda and now the samples work but not my programs. I still get the same error about DirectNotifyGlobal. I have done some experimenting and found out that if I put my own python scripts into a different folder than Panda3d’s and put one of the Panda tutorial scripts also there and run it with ppython I get the same error. But when I remove my own script from the folder and try to run the tutorial script again it seems that it would work (except that it can’t find the models it tries to load).

Here’s the program I’m trying to run that generates the error:

import direct.directbase.DirectStart 
from direct.showbase.RandomNumGen import * 

rn= RandomNumGen(5) 
print rn.randint(4,5) 


And here’s the full error message:

C:\Panda3D-1.1.0\bin>ppython "c:\mypanda\"
DirectStart: Starting the game.
Traceback (most recent call last):
   File "c:\mypanda\", line 10, in ?
      import direct.directbase.DirectStart
   File "C:\Panda3D-1.1.0\direct\src\directbase\", line 3, in ?
      from direct.showbase import ShowBase
   File "C:\Panda3D-1.1.0\direct\src\showbase\", line 6, in ?
      from pandac.PandaModules import *
   File "C:\Panda3D-1.1.0\pandac\", line 5, in ?
      from libdirectModules import *
   File "C:\Panda3D-1.1.0\pandac\", line 8, in ?
      from direct.directnotify.DirectNotifyGlobal import directNotify
   File "C:\Panda3D-1.1.0\direct\src\directnotify\", line 3, in ?
      import DirectNotify
   File "C:\Panda3D-1.1.0\direct\src\directnotify\", line 5, in ?
      import Notifier
   File "C:\Panda3D-1.1.0\direct\src\directnotify\", line 6, in ?
      from direct.showbase import PythonUtil
   File "C:\Panda3D-1.1.0\direct\src\showbase\", line 9, in ?
      import random
   File "c:\mypanda\", line 11, in ?
      from direct.showbase.RandomNumGen import *
   File "C:\Panda3D-1.1.0\direct\src\showbase\", line 3, in ?
      from direct.directnotify import DirectNotifyGlobal
ImportError: cannot import name DirectNotifyGlobal

Strange. Now it works. I made another test program that only loaded and displayed a model. That program did work. Then I included the RandomNumGen and its import statement and it worked too. When I commented out the other code and left only the random number generating code it still worked. I noticed that earlier a compiled python file was created when I tried to run the unworking random number program but now it doesn’t get created.

Here is the now working program:

import direct.directbase.DirectStart
#from pandac.PandaModules import *
#from direct.interval.IntervalGlobal import *
#from direct.gui.DirectGui import *
from direct.showbase.RandomNumGen import *

#bird = loader.loadModel('bird')

#lens = base.camLens

r = RandomNumGen(5)
print 'random number: ', r.randint(1,6)


Sigh All the problems came back when I tried to run the random number generation program:

import direct.directbase.DirectStart 
from direct.showbase.RandomNumGen import * 

rn= RandomNumGen(5) 
print rn.randint(4,5) 


The Panda samples and all of my programs became unworking again and the only fix I was able to figure out was to uninstall and reinstall Panda and then NOT run this code.

OK. I did some more experiments and it seems that the problem was really caused by the filename I was using for the random number program. I had named it “” and when I changed the name to “” everything worked again. There’s a file named “” in Panda3D-1.1.0\python\Lib folder and I think this may be the reason my program didn’t work with the name

Wow, that’s a good one. I was scratching my head the whole way through while reading through your journey. Good job figuring it out! Yep, in hindsight it’s all perfectly clear– is a system Python module; lots of system files probably try to import, and if they accidentally pick up a different copy (like yours) instead, they will certainly crash with a strange error message.

This sort of problem is a fundamental problem with Python (and with most any programming language). You have to be careful not to duplicate any of the system file names. Unfortunately, it’s too easy to do this accidentally, and the failure mode is so bizarre that it’s almost impossible to realize when you have done it–so kudos to you for finding it!