How to run python 3 script in python 2.7 in maya

How to run python 3 script in python 2.7 in maya

yadavchandrabhan59
Contributor Contributor
1,958 Views
9 Replies
Message 1 of 10

How to run python 3 script in python 2.7 in maya

yadavchandrabhan59
Contributor
Contributor

I have a script of software bridge cascaudour but it wasnt work on my maya 2020 version. I have attched script please suggest how to run or work on this.

0 Likes
1,959 Views
9 Replies
Replies (9)
Message 2 of 10

jmreinhart
Advisor
Advisor

I don't have Maya 2020 installed on my machine so I can't test this myself but you could try adding some code to the top of the script to import the "future" module which will allow some python3 functionality to be used in python2. 

 

If that doesn't work you modify the code based on what is not working (fixing syntax differences and stuff).

 

Or you could upgrade to windows 2022 where python 3 is standard.

0 Likes
Message 3 of 10

yadavchandrabhan59
Contributor
Contributor

how can I modify the code based on what is not working (fixing syntax differences and stuff) I dont know coding can you help me with 

0 Likes
Message 4 of 10

jmreinhart
Advisor
Advisor

When you run the code do you get errors? If so you can use info like this: https://portingguide.readthedocs.io/en/latest/ to help you make the changes necessary to work in Python3.

 

If you're not getting errors then you'll need to manually check through the code for any syntax whose behavior would have changed between py2 and py3 (you can refer to that same link to know what to look for).

 

 

0 Likes
Message 5 of 10

yadavchandrabhan59
Contributor
Contributor

I have tried this with chat gpt several changes but it was not working....

0 Likes
Message 6 of 10

jmreinhart
Advisor
Advisor

When you try to run the code, are you getting errors? or are you getting the incorrect result?

0 Likes
Message 7 of 10

yadavchandrabhan59
Contributor
Contributor

The script I have attached above when script run correcting there was installing window pop up automatically and now when I run script there was an error written in lower tab syntax error exactly

0 Likes
Message 8 of 10

jmreinhart
Advisor
Advisor

What is the error message that it is giving you?

0 Likes
Message 9 of 10

yadavchandrabhan59
Contributor
Contributor

import maya.app.general.executeDroppedPythonFile as myTempEDPF
myTempEDPF.executeDroppedPythonFile("C:/Users/CHANDRABHAN/Downloads/maya_casc_installer.py", "")
del myTempEDPF
# Error: SyntaxError: file C:\Program Files\Autodesk\Maya2020\Python\lib\site-packages\maya\app\general\executeDroppedPythonFile.py line 66: invalid syntax #

0 Likes
Message 10 of 10

jmreinhart
Advisor
Advisor

So the area around line 66 looks like this

try:
    #python2
    reload
except:
    #python3
    from importlib import reload

 

I don't have 2.7 installed on my computer so unfortunately I cannot test it myself, but  you should be able to remove that section completely since reload is a standard part of python 2.

0 Likes