Home Coding, Scripting, Shaders

[MAYA] How to convert Python 2 script to Python 3 [CREASE+ As an example]

polycounter lvl 9
Offline / Send Message
noizekrafft polycounter lvl 9

Maya 2023 dont work with Python 2 scripts (when you try to run them, you have syntax error, it means this is Python 2 code), but we can convert them automatically using Windows command line.

Sometimes unfortunately its not help, but if you, as i am not a coder, you can try)

  1. Run Windows command line (win+R and type cmd, then Enter)
  2. Navigate to folder, when .py files are stored. (cd C:\myscripts\CreasePlus for example, to change disc, type disc letter. then : (D: for example))
  3. Type 2to3 . -w

for example

D:\Temp\CreasePlus 2to3 . -w

and hit Enter

it convert automatically all files in that folder, and create a .py.bak files (it must be original backup files), but better make a copy of that folder before conversion

Now you can copy these files to folder that is specified in the instructions of original scripts (usually \Documents\maya\2023\scripts)

I convert like this CREASE+ scripts, and they works!)

But, i have eror Error: RuntimeError: file <maya console> line 6: Plug-in, "CreasePlusNodes.py", was not found on MAYA_PLUG_IN_PATH

To fix that, i go to \Documents\maya\2023 and in file Maya.env add path to folder stores CreasePlusNodes.py file

MAYA_PLUG_IN_PATH=C:\Users\%%your user name%%\Documents\maya\2023\scripts\CreasePlus

btw, i upload in to gdrive, if you need)

https://drive.google.com/file/d/1nGwdXJyHbglh7rvyIN4Zd490KcrkpHnd/view?usp=share_link

Replies

  • illusionist
    Options
    Offline / Send Message
    illusionist polycounter lvl 8
    Hi, I saw many youtube videos, even I see the python files in my maya install folder (pip, 2to3...) but when I run the scripts I got always this error: '2to3' is not recognized as an internal or external command, operable program or batch file.
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    https://matiascodesal.com/blog/how-to-convert-maya-python-2-code-to-python-3/
    there's a bit more detail on that link

    If you follow the instructions in the post above as written you'll be running the default windows python interpreter (whatever version that is) which won't have the 2to3 library installed. 
    Instead you need to use the supplied maya interpreter - which does have the 2to3 library installed .  You do this by running the command from the folder in which mayapy is installed

    * disclaimer  : Haven't tried it, have no intention of trying it

Sign In or Register to comment.