"Hello World" program Doesn't Work

I tried running the “Hello world” python script, but I got this error:

Traceback (most recent call last):
File “C:\Panda3D-1.9.4-x64\pandaTest.py”, line 1, in
from direct.showbase.ShowBase import ShowBase
File “C:\Panda3D-1.9.4-x64\direct\showbase\ShowBase.py”, line 355
raise StandardError, “Attempt to spawn multiple ShowBase instances!”
^
SyntaxError: invalid syntax

But that’s from running it with python 3, if I run it through python 2 I get a completely different error,

Traceback (most recent call last):
File “C:\Panda3D-1.9.4-x64\pandaTest.py”, line 1, in
from direct.showbase.ShowBase import ShowBase
File “C:\Panda3D-1.9.4-x64\direct\showbase\ShowBase.py”, line 12, in
from panda3d.core import *
ImportError: DLL load failed: %1 is not a valid Win32 application.

I wanna learn how to make things with panda3d and python, but I can’t get this copy/pasted hello world to work?

from direct.showbase.ShowBase import ShowBase    
   
class Game(ShowBase):    
  def __init__(self):    
      ShowBase.__init__(self)    
      print ("Hellow world")    
   
game = Game()    
game.run() 

it works?

Or show the code, it happens when ShowBase is called several times.

And you need to run through that python, which is in the panda folder. Or for which you installed a panda.

You say show the code, that’s literally all the code there is, copied directly from the website’s “Hello World” thing. I already had python 2 installed before installing panda, could that be related?

The panda is going for a certain python. Panda is essentially a python package, so you need to use a python postponed with a panda. Or install via pip for your python, like so:

python -m pip install --extra-index-url https://archive.panda3d.org/ panda3d

This is very strange. That error usually occurs when the code is being run more than once, or there is a stray import of the DirectStart module.

Could you indicate how precisely you are running the code? Are you calling ppython pandaTest.py on the Windows command prompt?

I’m wondering if somehow the ShowBase files were corrupted. It looks very strange that the error would appear upon importing ShowBase.py, even though the error is not being raised at the module level. You could try replacing direct/showbase/ShowBase.py with the proper version for 1.9.4 just in case:
https://raw.githubusercontent.com/panda3d/panda3d/release/1.9.x/direct/src/showbase/ShowBase.py

I got it to work.

What I was doing before was the file was in the panda3d directory, and to run the program I ran the python 2 IDLE, after uninstalling python 2 then using cmd to “ppython” it, it worked. Is there a way to do this without having to cmd ppython every time?

You could set up your editor program to be able to run your game after pressing a shortcut, or you could create a .bat file that you can double-click to run it.