Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Python 2 not working Maya 2022

Python 2 not working Maya 2022

InNeedOfHelp
Advocate Advocate
23,110 Views
16 Replies
Message 1 of 17

Python 2 not working Maya 2022

InNeedOfHelp
Advocate
Advocate

I'm not too familiar with python past the basics but I've got a bunch of python 2.7 scripts I'd like be able to use with Maya 2022. I've tried both methods listed in the docs for running maya in python 2 mode, first by launching maya via command line with '-pythonver 2'. In this case maya fails to launch, I see the slash screen for a moment and then it crashes. Using the other method of setting an environment variable 'MAYA_PYTHON_VERSION=2',  Maya launches fine but I'm not sure how tell if it worked. In maya 2020 running the following returns the python version:

 

import sys
ver=sys.version
print(ver)

 

In Maya 2022 it doesn't return anything, in fact even just print('hello') doesn't print anything. I'm not sure how else to tell what version other than trying to run an old script. The few I've tried (all of which work 2020) return errors so I assume I'm still in python 3 mode. 

0 Likes
Accepted solutions (2)
23,111 Views
16 Replies
Replies (16)
Message 2 of 17

justin5PV6Q
Participant
Participant
0 Likes
Message 3 of 17

WindXu
Alumni
Alumni
Accepted solution

Hi,

I think you run into an issue which is known on our side, that is: Maya crashes with starting in Python 2 mode if MAYA_NO_CONSOLE_WINDOW is set.

So I believe MAYA_NO_CONSOLE_WINDOW is set on your machine. If you unset it, Maya 2022 should not crash when starting in Python 2 mode.

You can find this limitation on Maya 2022 help -> Maya 2022 Known Issues.

This issue has been fixed on our side and the fix will be in next Maya update.

 

As for environment variable 'MAYA_PYTHON_VERSION=2' failing to work for you, that could be because you set the environment variable in Maya.env file.  This is not expected to work, because when Maya reads Maya.env file, it has already been in starting process and won't be able to switch between Python 2 and Python 3.

In order to use MAYA_PYTHON_VERSION, you need to

  • Set it in your system environment 
  • Or in terminal (command prompt on Windows) before running maya executable from there

Hope it helps,

 

Thanks

0 Likes
Message 4 of 17

Hai__Nguyen
Participant
Participant

So there's no way we can get back to Python 2.7 while using Maya 2022? I would love to try 2022 too but I got a bunch of tools written in Python 2.7 so they all don't run anymore 😞

Message 5 of 17

WindXu
Alumni
Alumni

Yes, you can still run Maya 2022 in Python 2 mode as long as you don't have environment variable MAYA_NO_CONSOLE_WINDOW set on your machine.

 

To run Maya 2022 in Python 2, you can do one of followings:

  • Start Maya with "-pythonver" flag.  For python2, it is "maya.exe -pythonver 2".
  • Set environment variable MAYA_PYTHON_VERSION=2 and start Maya. As I mentioned above,  MAYA_PYTHON_VERSION should NOT be set in Maya.env file.
0 Likes
Message 6 of 17

InNeedOfHelp
Advocate
Advocate
Accepted solution

I see, that explains that aspect. But still using the other methods maya would fail to load. Seems not many others have run into this but in my case it turns out Maya won't start in python 2 mode unless run as admin, while python 3 mode does not require this.

Message 7 of 17

sigridEDDGA
Contributor
Contributor

This worked for the most part, however we still have some PCs running windows 7. They are able to run maya 2022, but when we add in the environment variable suddenly maya can't open anymore. Do you have any work around for this?? thank you:)

0 Likes
Message 8 of 17

WindXu
Alumni
Alumni

You mean after adding MAYA_PYTHON_VERSION=2, Maya 2022 won't start on Win 7? 

I cannot think of any reason this environment variable will stop Maya from starting, unless you have MAYA_NO_CONSOLE_WINDOW set on your machines.  Is that the case?

If yes, you need to remove MAYA_NO_CONSOLE_WINDOW from your systems. Now Maya 2022 provides a "Windows->Output window" menu to hide/unhide output window. 

 

If you don't have MAYA_NO_CONSOLE_WINDOW set, if you try starting Maya 2022 with flag "-pythonver 2", can Maya start?

0 Likes
Message 9 of 17

mspeer
Consultant
Consultant

Hi!

@WindXu 

I can confirm this.

On Windows 7 Maya 2020 crashes when trying to start Maya 2022 with Python 2 enabled.

(crash at: mtoa_api.dll, OpenMaya.dll,...)

The problem is related to the USD plug-in and the Arnold plug-in.

If both plug-ins are enabled then Maya 2022 with Python 2 mode will crash at startup on Windows 7.

 

Solution:

a) Disable auto load for mayaUsdPlugin.mll, or

b) Disable auto load for mtoa.mll

Message 10 of 17

WindXu
Alumni
Alumni

@mspeer  Thanks for the info. It is strange that USD and Mtoa Plugins will crash Maya 2022 in Python 2 mode when starting up on Win 7.   So the following combinations work for you, right?

  • Win 7 + Maya 2022 Python 3 + USD and MtoA
  • Win 10 + Maya 2022 Python 2 and Python 3 + USD and MtoA

 

@sigridEDDGA Is your crash the same as @mspeer 's?  Could you please try disabling auto load for mayaUsdPlugin.mll and mtoa.mll and see whether it fixes the crash on your Win 7 machines? Thanks

Message 11 of 17

mspeer
Consultant
Consultant

Hi!

 

- Win 7 + Maya 2022 Python 3 + USD and MtoA

Yes, this works.

 

- Win 10 + Maya 2022 Python 2 and Python 3 + USD and MtoA

On the Windows 7 computer there is no Windows 10 is installed, so I can't answer this.

Message 12 of 17

sigridEDDGA
Contributor
Contributor

Hi @WindXu 

 

There is no  MAYA_NO_CONSOLE_WINDOW variable on any on the machines and it seems I do have the same issue as @mspeer.

 

Yes, these combinations worked without any issue:

Win 7 + Maya 2022 Python 3 + USD and MtoA

Win 10 + Maya 2022 Python 2 and Python 3 + USD and MtoA

 

I tried to disable auto load for mtoa on one win7 machine and usd on another win7 machine and for both of those I could open maya 2022 with python 2 using the environment variable. And just for the fun of it I also tried unloading both the plugins and that also works.:) So it seems indeed to be when both the arnold and usd plugins are loaded I can't open maya 2022 on a win7 machine in python 2 mode, at least using the environment variable method. 

Message 13 of 17

WindXu
Alumni
Alumni

@sigridEDDGA @mspeer Thanks for the confirmation. This seems more of an USD or MtoA plugin issue than Maya one to me. Besides, Win 7 is not supported by Maya any more. So I am not sure what we can do for the crash on Win 7 with Python 2.

I will let the team know about this. Let's see what can be done.

 

Thanks

Message 14 of 17

sunny_muthreja
Participant
Participant

If you want to launch Maya 2022 with Python 2, I'm leaving an article here I wrote on my artstation:

https://www.artstation.com/sunnymuthreja/blog/2WoQ/maya-2022-how-to-run-python-2-scripts

 

I've set it up the other day. every python 2 script works fine except animBot which has some licensing issue.

Message 15 of 17

sigridEDDGA
Contributor
Contributor

But this fix only works when maya is launched so for when rendering through a renderfarm when maya is not technically being opened I am assuming this fix won't work. And honestly for my part we have kind of realised it is a bit to early to switch to maya 2022 as redshift hasn't realised a supported version yet anyway. So hopefully within a couple of weeks some of the issues are fixed:) 

0 Likes
Message 16 of 17

rossddaniel
Explorer
Explorer

I can confirm I had this error without MAYA CONSOLE variable and  python 2 only worked when I turned off USD plugin.

0 Likes
Message 17 of 17

hushsmihi
Explorer
Explorer

how do you "Set environment variable MAYA_PYTHON_VERSION=2 and start Maya."

0 Likes