Migration to Python 3

No, that’s not what I’m talking about. I don’t intend to make the source compatible with both Python 2 and 3 (though “as close as we can comfortably get” sounds like a nice long-term goal). But there are two problems with using our source in Python 3 as it is:

  • (1) We use Python 2’s syntax and idioms, obviously.
  • (2) We use old APIs that were mostly already deprecated in Python 2.

Now (1) is really easy to solve, which is already more or less taken care of by the use of lib2to3. However, 2to3 doesn’t touch the more complicated things, such as our use of the “new” module or our use of a custom “cmp” function in sort(). In these cases there is usually no straightforward substitution. But we can manually replace these things with code that uses a newer API (one that wasn’t removed in Python 3) while still using Python 2 syntax and idioms.

So 2to3 will still be required, but 2to3 and a few module import changes are not enough by itself.

Ok, thanks for clarifying. I’ll be able to work on this in the coming weeks; what’s the goal in terms of time? Is there any particular release you’re aiming to have this ready for?

No, this is more like a pet project to me that I just spontaneously decide to have time for once every blue moon.

Thanks for the help!

I just toyed a bit more, and it turned out to take surprisingly few changes to get genPyCode to work. In fact, I not only have the pandac.PandaModules imports working, even “from direct.directbase import DirectStart” now works. :slight_smile:

I suppose the next step is to try and get some of the sample programs to work.

That’s good to hear; if you’ve got the core working then I guess the rest would just be the grunt work of going through all the other modules/samples and getting them working as well. Are the new py3 support changes in the latest buildbot version or would I have to build from the CVS version to start testing on this?

Well, all of the buildbot builds are compiled with Python 2, not 3. You’d have to grab the latest code from CVS in order to build with Python 3 support. You have to replace the Python version in thirdparty/win-python-x64 (or win-python for 32-bit systems) simply by removing that directory, running the appropriate Python 3 installer and pointing it at that directory (hit “install for this user only”).

You will need to see this in order to compile latest CVS:

It’s amazing to see progress on this 8)

Just for information:


Thanks for the link, definitely an interesting blog; I think a lot of that reasoning would also apply to panda3d, but there are a couple of differences. First of all, I’m guilty of mis-naming this thread, it really should have been something like “Branching to Python 3”, because I don’t think the goal here is to permanently migrate the entire code base to py3, but to give users the option of working with panda3d using py3 if they want. Also, for Eve the end user is a game player, so the language choice is not relevant to them, but for Panda3d obviously the end user is another developer so language choice has more bearing.

For myself, all my other projects are in py3 so it’s really just a matter of convenience; I have no problem working in py2, but the editor I use is in python and some features fail if I don’t use the version that matches the code I’m working on.

I think my purpose was to say, that nothing is urgent around python 3, and there is lot of thing to develop around current version that developer requires.
To my point of view, I prefer enhancement around panda against upgrade to python 3 :smiley:

I agree with the view that Python 2.7 is still the industry standard and there’s not much reason or motivation to migrate now aside from the novelty aspect. However, since an eventual migration to Python 3 is inevitable, we might as well just work a bit on it here and there for the benefit of enthusiast’s convenience and to make it easier for that future moment when there is a real demand for Python 3.

As I said earlier, though, it’s not a high priority for me, as there are more important things to do, but I do keep it somewhere in the back of my mind since it’ll have to happen sooner or later anyway.

However, count me into the camp of people who would like to see a Python 2.8, even if that is very unlikely to happen.

Last post was quite some time ago… So… How’s the progress? :slight_smile:

I’ve been using Panda with Python 3 for a while, and it seems to work pretty well. There are still a whole lot of trivial fixes to be made to the ‘direct’ tree (which is implemented in Python) though, to take out all the Python-2-isms.

This is very nice to hear. Maybe 1.9 will support it officially, or it’s some like in later releases…?

2.0 is the goal for official Python 3 support.

Just wondering.

Can I safely use the latest revision from github.com/panda3d/incremental
or is there already some Python 2.7.x related deprecation taking place?

I remember one commit message saying it would remove “Python 2.x isms”. Does this change any of the usable syntax or is it merely backend related?

Python 2.7 is still supported and will be supported for a long time. No features from Python 2.7 will be deprecated any time soon.

The only thing I changed is syntax that only worked with Python 2.7 (which was already deprecated in 2.7 to begin with), which I replaced with syntax that works in both Python 2.7 and 3.3.

Just FYI for people following this: I finally tracked down and fixed the “Invalid access to memory location” issue that prevented the Python 3 build from working on Windows. So the Python 3 port seems to work on Windows as well now.

Sorry, I was occupied by a new job for the past year and wan’t in position to program much. I’m glad to see you basically have this working though; I’ll be reviving my panda3d project over the winter and since it was always my goal to write it in python 3 I’ll definitely give this a try.

Excellent. There are still a lot of things to fix on the Python side. I imagine a lot of patches will be necessary before it becomes stable. :slight_smile: