How to Launch Maya 2022 With Python 2 if You Are Not Ready for Python 3
While I’m excited and gladly welcome Python 3 for Maya, I know not everyone may be ready for it. Here I highlight and walk you through how to launch Maya 2022 with Python 2 instead.
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.
OPTION 1: Use the -pythonver flag#
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
- Right-click on your Maya 2022 shortcut and click Properties
- On the Shortcut tab, scroll the Target field all the way to the right
- At the very end of the Target field leave a space after the quotation mark and add
-pythonver 2
: - Click OK
Now, when you launch Maya, you should get Python 2.
OPTION 2: Set the MAYA_PYTHON_VERSION environment variable#
The other way is to set the MAYA_PYTHON_VERSION environment variable. There are 3 variations of this method:
- Set MAYA_PYTHON_VERSION=2 as a system environment variable so that Maya 2022 picks it up no matter how you launch Maya.
- Set MAYA_PYTHON_VERSION=2 in a command window and then launch Maya from that same terminal.
- Set MAYA_PYTHON_VERSION=2 and launch Maya from a script file. (e.g. a batch file)
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"
Verify you’re using Python 2 after Maya launches#
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)
2.7.11 (default, Jul 1 2016, 02:08:48) [MSC v.1900 64 bit (AMD64)]
Environment Variable vs Flag Priority#
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.
Conclusion#
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.