I saw that there are current _PY2 releases for windows but not for Mac OS. Is it possible to get a current yet stable standalone version which I can code my experiment in using Python2? I’d have to change a lot in my code to make it fit Python3 as the experiment had been created when PsychoPy3 was not yet out.
It looks like the last Python 2 release for Mac was in August of 2018. It wasn’t a deliberate decision to drop support – it just became increasingly difficult to maintain due to issues with other dependencies. It is hard to justify putting much time and effort into overcoming such issues, as more and more will inevitably arise as Python 2 support drops off in the rest of the eco-system upon which PsychoPy relies.
PsychoPy’s Python 2 version for Windows will eventually disappear too (probably in a more planned fashion). So the solution for everybody who hasn’t done so already really is to migrate to Python 3. I did that with some old but substantial and relied-upon stable code earlier this year - there were more issues than I’d anticipated, but they were all minor and easily fixed. And Python 3 does make it all worth it.
There are a lot of migration guides out there, and even some automated tools that can identify issues.
Thank you for the answer, Michael. I tried searching for migration guides and automated tools but came up with nothing, could you please point me to one or two? That would be very nice.
If you use an editor like PyCharm that does inline code listing, it will pick up a lot of things that don’t meet the current Python 3 standard and give little inline visual indications that need to be attended to.
But a more comprehensive solution could be to run Python’s built-in 2to3. This is a script that will process your existing Python script and output a version translated for Python 3. I’m not sure how interactive it is, which may limit how useful it is in actually learning what needs to be changed, and keeping control over what is changed.
There are some useful pointers on this SO page as to how to get started with it (in this case, ignore the references to PyCharm, it is a red herring here):
To be honest, I’ve done conversions by just repeatedly running the scripts under Python 3 and dealing with the errors as they arose. As I found out the common issues, it was easy to do a find and replace to deal with them in bulk. This process was a bit laborious but kept me in control of knowing what was being changed and why.
In effect, you’ll probably be surprised by how simple it all is. A lot of it is changing print statements into print()functions, removing all xrange() in favour of range(), no longer needed to use u'' prefixed strings, etc. If you deal with things like serial ports and other low-level text processing functions, you might find yourself having to make distinctions between when a string is a string, and when it is bytes, which can be the trickiest thing to get to grips with.
I only found one subtle bug, related to treating the result of a Python 2 range() as a simple modifiable list, while in Python 3, range() returns an iterator.