# _ _ ____ ___ _ ____ ____ ___ ____ ____ # # |\/| |__| | | | | | | \ |___ [__ # # | | | | | | |___ |__| |__/ |___ ___] # # #
# _ _ ____ ___ _ ____ ____ ___ ____ ____ # # |\/| |__| | | | | | | \ |___ [__ # # | | | | | | |___ |__| |__/ |___ ___] # # #
I highly recommend starting to look at moving to Python 3. I've written a guide for auto-converting your Maya Python 2 code to Python 3 with considerations for cross-compatibility between the two versions. If you're not quite ready to port your code and want to start trying out Maya 2022 without having to worry about Python 3, I thought this post might help you out. These instructions only work for Windows and Linux since Maya 2022 for those operating systems includes Python 2 and Python 3. Maya 2022 for macOS only includes Python 3.
Autodesk included a new -pythonver flag that you can use to launch with Python 2. You'll need to launch Maya from the commandline or create a batch or script file to include the flag. It should look like this:
maya.exe -pythonver 2
If that's too much and you're on Windows, you can make it a bit easier on yourself by editing you Maya 2022 shortcut to do the same.
Now, when you launch Maya, you should get Python 2.
The other way is to set the MAYA_PYTHON_VERSION environment variable. There are 3 variations of this method:
NOTE: Setting the MAYA_PYTHON_VERSION in your Maya.env file doesn't appear to work.
For variations #2 and #3, it would look something like this:
set MAYA_PYTHON_VERSION=2
"C:\Program Files\Autodesk\Maya2022\bin\maya.exe"
You can also use this environment variable in your Maya modules or Python code to determine what Python files to import depending on if you're running Python 2 or Python 3. More on that in a follow-up blog post.
To make sure your changes worked or as a sanity check, you can run these two lines in the script editor:
import sys
print(sys.version)
It should print out something like this letting you know you're using Python 2.7.11:
2.7.11 (default, Jul 1 2016, 02:08:48) [MSC v.1900 64 bit (AMD64)]
Lastly, I would like to note that the flag takes priority over the environment variable. Use this to your advantage if you want to have multiple levels of overrides for your Maya wrappers. The MAYA_PYTHON_VERSION within Maya will always give you the final resolved value. For example, if you set the environment variable to 2 and the flag to 3, MAYA_PYTHON_VERSION will be 3 when you're in Maya.
Hope that helps you start using Maya 2022 without worrying about Python 3 for now. I encourage you to take a look at how to convert Maya Python 2 code to Python 3 and start making plans to convert your code so you can start enjoying the benefits of Python 3.
© 2022 Matias Codesal