Mati Codes
# _  _ ____ ___ _    ____ ____ ___  ____ ____ #
# |\/| |__|  |  |    |    |  | |  \ |___ [__  #
# |  | |  |  |  |    |___ |__| |__/ |___ ___] #
#                                             #
# _  _ ____ ___ _    ____ ____ ___  ____ ____ #
# |\/| |__|  |  |    |    |  | |  \ |___ [__  #
# |  | |  |  |  |    |___ |__| |__/ |___ ___] #
#                                             #

March 25, 2021

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

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.

  1. Right-click on your Maya 2022 shortcut and click Properties
  2. On the Shortcut tab, scroll the Target field all the way to the right
  3. At the very end of the Target field leave a space after the quotation mark and add -pythonver 2
    1. add pythonver to maya 2022 shortcut
  4. 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:

  1. Set MAYA_PYTHON_VERSION=2 as a system environment variable so that Maya 2022 picks it up no matter how you launch Maya.
  2. Set MAYA_PYTHON_VERSION=2 in a command window and then launch Maya from that same terminal.
  3. 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"

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.

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)

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)]

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.

>>>

Tags

python, maya, autodesk, python 3 adoption, maya 2022

Comments

Leave a Reply

>>>
>>>
>>>
>>>
cancel