AttributeError: 'module' object has no attribute 'Thread

So I’ve been trying to get py2exe to work with Panda and I’ve been running into numerous problems.

I’m current getting the following error when I try to run the executeable:

Here’s the traceback:

File "Server2.py", line 1, in <module>
  from direct.showbase.DirectObject import DirectObject
File "direct\DirectObject.pyc", line 7, in <module>
File "direct\showbase\MessengerGlobal.pyc", line 5, in <module>
File "direct\showbase\Messenger.pyc", line 8, in <module>
File "direct\stdpy\threading.pyc", line 29 in <module>
File "direct\stdpy\thread.pyc" line 22, in <module>
AttributeError: 'module' object has no attribute 'Thread'

Any ideas?

# Import PandaModules as pm, so we don't have any namespace collisions.
from pandac import PandaModules as pm

# These methods are defined in Panda, and are particularly useful if
# you may be running in Panda's SIMPLE_THREADS compilation mode.
forceYield = pm.Thread.forceYield
considerYield = pm.Thread.considerYield

I opened thread.pyc and went to line 22 that is mentioned. This is the specific line:

forceYield = pm.Thread.forceYield

Right above that it imports PandaModules as pm

So I went looking in the PandaModules.py file and here’s what it shows:


try:
  from libpandaexpressModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandaModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandaphysicsModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandafxModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libp3directModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libp3visionModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandaskelModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandaeggModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

try:
  from libpandaodeModules import *
except ImportError, err:
  if "DLL loader cannot find" not in str(err):
    raise

From what I can tell, thread.pyc thinks that PandaModules.py has a reference to Thread somewhere, but I don’t see it. So does that mean PandaModules is missing some code? Is there some kind of threading DLL that is supposed to get imported in PandaModules.py?

PandaModules.py imports all of the C++ symbols from Panda. In particular, Thread comes in from the line:

from libpanda import *

If there’s no “Thread” symbol in PandaModules.py, it means there is no C++ Thread class defined in libpanda.dll.

This is very strange, because the Thread class is defined even if you have compiled a custom version of Panda without thread support. So something is wrong with your build of Panda. Maybe it defines no symbols at all? Or maybe you are running with the wrong version of Panda or some such.

How many versions of Panda do you have installed on your machine, and where did they come from?

Edit: on second thought, I see you are having these problems with py2exe. This probably just means that you don’t have the correct paths specified to locate libpanda.dll in the first place, and for some reason we’re squelching the import error that you should have gotten for libpanda.dll.

David

I’m using Panda 1.7.0 which I downloaded from this site, I don’t have any other versions and I’m using the python that came with it.

I’ve tried numerous versions of the panda.pth file, currently I have it set to:

C:\Panda3D-1.7.0\
C:\Panda3D-1.7.0\lib\
C:\Panda3D-1.7.0\bin\

But I’ve tried several different variations of it based on reading other threads here without any luck.

However I did manage to get an executeable application with packpanda, so I think I’ll just stick with the built-in Panda stuff for this unless I can get some direction here.

I’m going to try and get pdeploy working here too, as I want to test out all the options here. But so far it looks like py2exe isn’t working for me.

Note that, if you’re using packpanda, then you are actually using py2exe. Packpanda is just a thin wrapper around py2exe that sets up all the paths correctly. There’s no need to reinvent packpanda yourself.

David

Uhm, are we talking about the same packpanda? Did the behaviour change? As far as I know, the packpanda in direct/src/directscripts does not use py2exe, it stores .pyc files.

Oh, huh, you’re right. I was getting py2exe confused with NSIS, my apologies.

Also, within Disney, we once used py2exe to package up our own games for distribution. But we switched to FreezeTool years ago.

Any of these tools are somewhat problematic to use with Panda (or with any C++/Python hybrid) because you have to deal with the dll’s as well as the pure Python code. It can be done, though; it just requires a good understanding of how the packaging tool in question works.

David