
We're looking at 2to3 first since it's at the core of futurize and modernize and the other tools adopt a similar script interface to run the conversion. If you're using the division operator in 2.7 and your code expected an integer result, in Python 3 you'll get a float result which may cause issues.
#MAYA 2022 PYTHON HOW TO#
The way I'm showing you how to use the conversion scripts will also create a backup in the process, but just the be on the safe side, it's not bad to keep another copy. Make sure you have a backup of the code you'll be converting.


Note that none of these libraries is a complete solution, but if you're lucky, they'll get the job done or get you most of the way there. I'm going to show you how to use the conversion scripts for these three methods and cover more in-depth the pros and cons for each.
#MAYA 2022 PYTHON INSTALL#
Lastly, the python-modernize library will also give you backwards-compatibility and only relies on the built-in six library as the compatibility layer, but you'll need to install python-modernize to get access to the conversion script. This sounds wonderful, but the catch is that to use it as intended your end-user needs to have the future python package installed in their older Maya installations or you need to provide the future package with your code. On the other hand, Maya 2022 also comes with the python-future library installed which uses 2to3 under the hood, but it can convert your code and make it backwards compatible with Python 2 with the futurize script. 2to3 focuses on porting your code to Python 3, but it does not attempt to make it backwards-compatible. Should I use 2to3, futurize, or modernize?Īs mentioned, Python 3 comes with a library called lib2to3 which as the name suggests converts Python 2 code to Python 3. I really recommend reading this blog post in its entirety before getting started to understand what changes are being made and there are a few scenarios that you'll want to consider. You can always go back and clean up your code as time allows and especially as you drop support for Python 2.
#MAYA 2022 PYTHON MANUAL#
You can achieve cleaner results with manual conversion, but I know that may not always be desired or practical. My goal with this blog post is to help you convert your code as fast a possible with the least amount of fuss while also showing you some options for maintaining backwards-compatibility with Python 2.

Take a look at the 2to3.py documentation which lists the fixes that it applies to get an idea of how big of a difference there is between Python 2 and Python 3. Python 3 includes a script called, 2to3.py, which handles automatically converting your code for a lot of the changes that occurred between Python 2 and Python 3. You may only be using a subset of affected libraries and features in your Maya scripts, but you're probably still going to want to avoid making the updates manually.

There are A LOT of changes between Python 2 and Python 3 and Python 3 code is not designed to be backwards-compatible with Python 2. Python 3 is finally here in Maya 2022! If you haven't converted your scripts to Python 3, I'll go over how you can automatically convert your Python 2 scripts and modules to Python 3.
