[Solved]wxPython and Panda3D integration

I am using Windows XP and the wx package would be installed under

C:\Python24\Lib\site-packages (default)

If I wish to use it under Panda3D, do I have to move the two installed folders (wx and wxPython) into Panda3D-1.2.3 ? under direct? or pandac ?

import wx” works fine under python but not ppython … :cry:

So after some trial, I had some further steps:

(1) I moved the folders “wx” and “wxPython” under


python24\lib\site-packages

to


\panda3d-1.2.3\direct\src

(2) seems like wxPython is an obsolete package (commented from the file init.py inside the folder), so we’ll use wx.

(3) if I changed my directory to c:\panda3d-1.2.3\direct\src, entered ppython interactive mode and type:


import wx

it would work.

(4) however, if my location was in other places than src folder, it would complained:


ImportError: No module named wx

(5) so I tried the following ways instead:


from direct import wx
from direct.wx import wx
from direct.wx import *

Neither of them would work, and they all complained about:


File "wx\__init__.py", line 42, in ?
ImportError: No module named wx._core

(6) It seemed that the problem was in the init.py file under wx. So I changed the code from


from wx._core import * 

to

from direct.wx._core import *
(or)
from _core import *
(or)
import _core

Again, neither of them worked; and unfortunately at this step, it would crash ppython(Panda).

(7) So, any ideas? eg., are there any system variables I need to set?

You shouldn’t need to move files around on your system, but you will need to make sure that wx and Panda are both installed into the same python tree together.

It’s possible to have multiple different versions of Python installed on one system at the same time, each of which has a different set of packages. When you run “ppython”, it automatically selects a particular version of Python that Panda has been compiled specifically for. Since “import wx” doesn’t work in that version, it follows that wxPython is not installed into that version of Python, which isn’t really surprising. On the other hand, when you run “python”, you get whatever version of Python happens to be first on your path, and “import panda” doesn’t work there, meaning that Panda is not installed into that version of Python, also not surprising.

If, and only if, these two different Pythons are actually the same numerical version (e.g. both 2.4.3, or whatever), then you can simply set your PYTHONPATH variable to point to one tree while you run the other one.

David

Thanks David. I still have some further questions:

(1) ppython --> “it automatically selects a particular version of Python”
does this refer to python24.dll file?

I forget to mention that in my preceding post, I am pretty sure there’s only one python24.dll file in my system, and it’s also the only python version I have --python 2.4.3-- , which is under Windows/system32.

I removed the one in panda3d/bin. Panda3D works perfectly.

(2) If I keep the the wxPython package in its orginal place (c:\python24\lib\site-packages), and set the Python Tree to:


set PYTHONPATH=c:\python24

Is this right?

(3) Then, what the import command should look like? (when using ppython)


import wx

or


from xxx.xxx.xxx.wx import *

Sorry if my understanding is wrong. I will try my best to explain well if you also have further question. :laughing:

Sorry, PYTHONPATH is the variable that names the directories that Python will search along foo foo.py whenever you do “import foo”. So, you should set PYTHONPATH to the path to the directory that contains wx, which in your case is c:\python24\lib\site-packages .

ppython sets up PYTHONPATH to point to the Panda3D installation. It also sets up PATH to find the python24.dll in your Panda3D installation, but if you remove that one and it still runs, it’s probably falling back to a different python24.dll that you’ve installed separately (e.g. in c:\python24).

You can find out what the PYTHONPATH is for your currently running version of Python like this:

python
>>> import sys
>>> sys.path

David

So… here’s my solution:

(1)
after ppython --> import sys --> sys.path , I got a list of the PYTHONPATH, and I noticed a path:


//c/Panda3D-1.2.3/bin/lib/site-packages

(2)So when installing wxPython, just point the destination to this folder, and you are all set.


import wx  #worked!

(3) Actually if trying again step (1), you’ll find a new path in it:


//c/Panda3D-1.2.3/bin/lib/site-packages/wx-2.6-msw-unicode

(4) To be honest it’s still confused, but works.

(5) I removed the entire python package except the python24.dll (2.4.3) left in windows/system32, as well as python24.dll (2.4.1 I guess bundled with panda3d-1.2.3) under panda3d/bin but left panda3d; since all of my job I need right now, is Panda.

Thanks David! :laughing: :laughing: :laughing: