Switching maya version 2020 to 2022

Hello there,

currently switching maya versions from maya 2020.4 to maya 2022, to convert from python 2 to python 3. I keep getting this error on all ragdoll functions and tools that have the ragdoll modules imported. Are there left over python 2 stuff sticking around in the api and will have have to do a fresh install of ragdoll?

# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
#     return original_import(name, *args, **kwargs)
#   File "C:\Users\Olivia\Documents\maya\modules\Ragdoll-2023_04_08\scripts\ragdoll\interactive.py", line 48, in <module>
#     from . import (
#   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
#     return original_import(name, *args, **kwargs)
#   File "C:\Users\Olivia\Documents\maya\modules\Ragdoll-2023_04_08\scripts\ragdoll\ui.py", line 18, in <module>
#     from . import (
#   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
#     return original_import(name, *args, **kwargs)
# ImportError: bad magic number in 'ragdoll.options': b'\x03\xf3\r\n' #

Hello hello, this is interesting! Yes, it seems likely related to Maya 2020 and 2022 having a different version of Python. Normally, whenever Python reads a module, like Ragdoll, it will create a cached version of said module. They will be called e.g.

  • my_module.py
  • my_module.pyc ← Cached

Python will then default to picking up the .pyc instead of the original module. The problem is these cached files only work with the Python that created them.

Normally, production systems don’t permit users writing into the modules folder, so studios would (should) not notice this. But for systems where users can write into the modules directory, especially home users with a personal install of Ragdoll, this can be a problem. I’m frankly surprised this hasn’t been an issue already!

Here are your options.

  1. Delete all .pyc files. They are not necessary (and never will be) (and never was in the first place, that’s a separate discussion)
  2. Write-protect your Ragdoll directory, prevent users/Maya from writing into it. This would already be the case for e.g. Maya’s native Python files, and should be the case here too.
  3. Prevent your system from making .pyc files in the first place.

The first option will solve the issue for Maya 2022, but you’d have the same problem again when launching 2020. The second and third options are your best bet, with write-protecting being the most common.

That third option is what I’d recommend (in addition to 2) and is what I’ve personally done for the past decade, thus alleviating this problem altogether. You can prevent it by setting the PYTHONDONTWRITEBYTECODE environment variable, or sys.dont_write_bytecode = True

Hope it helps, let me know if it worked!