Installing Panda3D on a Mac with Python 3.4?

I have a Mac with Yosemite (10.10) which has the default Python 2.7 install that comes with OSX, and I’ve also installed Python 3.4 using the recommended steps published at python.org (docs.python.org/3/using/mac.html). This allows me to use Python 3.4 when appropriate.

I’m still a bit new to python and the schism between 2./3., but wherever possible I’d prefer to use the most modern elements of python (3.) and so I’m trying to run Panda3D in a 3. version.

After a false start installing the 1.8 version and it not working in either 2.* or 3., I followed the suggestions in the forums to instead install the 1.9 Panda3D version, and now it works using Python 2., but I’d like it to also work with the Python 3.* version… what do I need to do?

I had the impression from the guides that the install would prompt me and ask which version I wanted to install for, but perhaps that is only on Windows, and not Mac…?

Would it be as simple as creating a .pth file with the appropriate entries? Is there a version of that somewhere with the appropriate entries already created?

You cannot use 1.8 or 1.9 with Python 3.4. The only version of Panda3D that will work with Python 3 is the latest master branch of Panda3D (labelled 1.10).

Go to GitHub to grab the latest version of the source code:
github.com/panda3d/panda3d
You must be sure to run makepanda with python3.4 to ensure that you are building Panda against Python 3.4. Also, makepanda by default assumes that you want to build for Apple’s copy of Python, so you may have to edit makepanda/makepandacore.py and change this line in the SdkLocatePython function:

    elif GetTarget() == 'darwin':

to this:

    elif False:

You’re the first person to ask for Python 3 support on Mac OS X, so the process is a little untested. Sorry about that. Maybe we’ll have development builds for Python 3 on Mac available on the download page soon.

No, it is not as simple as creating a .pth file. This is because different versions of Python are not ABI compatible, so a library compiled for Python 2.7 will not work for Python 3.4, and a library compiled for Apple’s Python won’t work with a Python version downloaded from python.org.

Hello,

Thanks rdb for the reply, it helped a lot. I followed your instructions on Mac OSX 10.11.1 and ran into a couple more minor issues but got it to build the installer in the end. Unfortunately examples won’t run…

This is what worked to finish building the installer:

  • install python 3.4 or above and make sure it’s the version for “python3” command

  • follow instructions at Installing Panda3D on a Mac with Python 3.4?

  • build with:

    python3.4 makepanda/makepanda.py --everything --installer

  • build will fail with error linking libboost_python

  • install boost using brew and with python bindings for python 3 with the following:

    brew install boost-python --with-python3

  • copy dylib to built/lib/:

    cp /usr/local/Cellar/boost-python/1.59.0/lib/libboost_python.dylib built/lib/

  • continue building panda3d:

    python3.4 makepanda/makepanda.py --everything --installer

  • at 100%, building the installer will fail when copying *.so

  • comment out lines for *.so and *.py in makepanda.py line 6867

  • continue building panda3d:

    python3.4 makepanda/makepanda.py --everything --installer

  • should finish building installer correctly

  • uninstall Panda 1.9 if need be:

sudo rm -rf /Developer/Panda3D
sudo rm -rf /Developer/Tools/Panda3D
sudo rm -rf /Developer/Examples/Panda3D
sudo rm -rf /etc/paths.d/Panda3D
sudo rm -rf /Library/Python/2.7/site-packages/Panda3D.pth
sudo rm -rf /usr/local/bin/ppython

  • use newly built 1.10 installer

The installer then worked great. I then tried to run the examples using ppython and ran into a segfault 11 for all of them. Using “ppython -v main.py” I saw there was a permission issue since /Developer/Panda3D was owned by root and not writeable by others. After sorting this out I’m still running into a segfault and even the -v option isn’t giving me much of a clue. At this point I’m stuck…

Hi,

The boost stuff can be avoided if you use --no-rocket. libRocket does not provide Python 3 bindings anyway.

Are you sure ppython links to the correct version of Python? Try running Panda with python3.4 explicitly.

Also, try running “pview”, to see if the crash is inside Panda3D itself or inside the Python modules.

At this point it would be helpful to get a stack trace of the crash. You can get one by running “gdb --args python3.4 main.py” and hitting “run” when the prompt appears. When it crashes, hit “bt” to get a stack trace.

Hi,

Thanks a lot for the quick reply! Here is a summary of the situation:

  • ppython does use python3.4:
$ ppython
Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
  • pview works! I can preview the .egg files shipping wit hthe examples.

  • I can’t get a stacktrace. I don’t gdb by default so I installed it via brew (even self-signed it as indicated). When I run the command you gave me it complains ppython (or python3.4 if I use it instead) are not in executable format and it can therefore not run them.

$ gdb --args python3.4 main.py
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin15.2.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4": not in executable format: File format not recognized
(gdb) 

I’m sorry, I’m here with my problems and not enough skills to resolve them, but I thought I’d let you know at least. If Launchpad is a better place to discuss issues like these feel free to let me know.

I think I’ll try to rebuild and specify --no-rocket as you had mentioned. Since I went with a dodgy “let’s just copy it from the brew install” that might screw things up…

If there is anything else you would like me to try, I’d be more than happy too. Otherwise I’d like to keep digging but I’m a bit lost… segfaults from python aren’t the easiest to figure out…

Cheers

Started re-building, no idea if this will be useful (I assume it’s just normal on MacOSX to have these missing) but this is how the build starts (before refactoring kicks-in):

$ python3.4 makepanda/makepanda.py --everything --installer --clean --no-rocket
Deleting built
Version: 1.10.0
Using Python 3.4
Target arch: x86_64
WARNING: Could not locate thirdparty package assimp, excluding from build
WARNING: Could not locate thirdparty package fftw, excluding from build
WARNING: Could not locate thirdparty package gles, excluding from build
WARNING: Could not locate thirdparty package gles2, excluding from build
WARNING: Could not locate thirdparty package egl, excluding from build
WARNING: Could not locate thirdparty package vrpn, excluding from build
WARNING: Could not locate pkg-config package gtk+-2.0, excluding from build

Alright, re-building without librocket I hit a problem when it puts the installer dmg together apparently related to PMW. So I just removed PMW from “thirdparty”, cleaned and re-compiled everything and hit a problem with the dmg step but the actual package was made and installs successfuly.

Trying to run examples still segfaults. I can’t get gdb going, presumably for this reason: stackoverflow.com/a/20975057

As suggested there I gave lldb a go and it actually works, but I don’t seem to be getting a very useful stacktrace:

$ lldb python3.4 main.py
(lldb) target create "python3.4"
Current executable set to 'python3.4' (x86_64).
(lldb) settings set -- target.run-args  "main.py"
(lldb) run
Process 36813 launched: '/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4' (x86_64)
Process 36813 stopped
* thread #1: tid = 0x18276e, 0x00007fff5fc01000 dyld`_dyld_start, stop reason = exec
    frame #0: 0x00007fff5fc01000 dyld`_dyld_start
dyld`_dyld_start:
->  0x7fff5fc01000 <+0>: popq   %rdi
    0x7fff5fc01001 <+1>: pushq  $0x0
    0x7fff5fc01003 <+3>: movq   %rsp, %rbp
    0x7fff5fc01006 <+6>: andq   $-0x10, %rsp
(lldb) bt
* thread #1: tid = 0x18276e, 0x00007fff5fc01000 dyld`_dyld_start, stop reason = exec
  * frame #0: 0x00007fff5fc01000 dyld`_dyld_start
(lldb) 

Not sure where to go from there. This is a bit of a shame as I’m gettinng the feeling it’s almost there… Please let me know if I can help any further.

Hmm, yes, that is not a particularly helpful stack trace. Hmm, “bt” only shows the stack trace for a single thread, perhaps you can try using “bt all” to get the stack trace for all threads.

Yep thought of that, unfortunately “bt all” gives me the same thing as I believe it means “for al threads” and there is only one.

Hmm… trying hard to come up with suggestions. Okay, try this:

otool -L /Developer/Panda3D/panda3d/core.so

(or, if you’re running Panda directly from the built directory:)

otool -L built/panda3d/core.so

This might shed light on how it’s linked against Python. I wonder if it’s perhaps linked to the Python 2.7 framework in some way.

Bingo! You’re right, it’s linked against 2.7:

$ otool -L /Developer/Panda3D/panda3d/core.so
/Developer/Panda3D/panda3d/core.so:
	@loader_path/../lib/libp3interrogatedb.1.10.dylib (compatibility version 1.10.0, current version 1.10.0)
	@loader_path/../lib/libpanda.1.10.dylib (compatibility version 1.10.0, current version 1.10.0)
	@loader_path/../lib/libpandaexpress.1.10.dylib (compatibility version 1.10.0, current version 1.10.0)
	@loader_path/../lib/libp3dtool.1.10.dylib (compatibility version 1.10.0, current version 1.10.0)
	@loader_path/../lib/libp3dtoolconfig.1.10.dylib (compatibility version 1.10.0, current version 1.10.0)
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.32.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)

I did definitely run makepanda using python3.4 though…

Ah! Makepanda uses “-framework Python”, which in your case probably happens to consider the system Python version before your own custom Python version.

I wonder how to force it to use a custom framework. Alternatively, perhaps you can link against libpython3.4.dylib (if you have that?) by finding these lines in makepanda.py

        if not PkgSkip("PYTHON"):
            if GetTarget() == "darwin" and not RTDIST and not PkgHasCustomLocation("PYTHON"):
                LibName("PYTHON", "-framework Python")
            else:
                SmartPkgEnable("PYTHON", "", SDK["PYTHONVERSION"], (SDK["PYTHONVERSION"], SDK["PYTHONVERSION"] + "/Python.h"), tool = SDK["PYTHONVERSION"] + "-config")

…and forcing it to follow the second case instead.

Sounds good, thanks for all the help! I’ve been tasked with taking the Christmas tree down :slight_smile: I’ll give this a go right after. Cheers!

Specifying the absolute path to the dylib instead of “-framework Python” worked!

Also of note:

  • I had re-installed python 3 using brew so I now have python 3.5.1, which I used for this, and so far examples run fine!
  • examples don’t run with ppython but run fine if I use “python3.5”

Thanks again for all your help, this is awesome. If I can in the next days I’ll make a branch on github to consolidate all these modifications in one public place that other people can grab.

Cheers!