Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to compile a Python script for Maya and create a .pyc file

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
YASUSHI_EMOTO
3775 Views, 3 Replies

How to compile a Python script for Maya and create a .pyc file

YASUSHI_EMOTO
Enthusiast
Enthusiast

I'm writing a Python script for Maya. I would like to compile and distribute it to make the code a little more confidential and to make it a little faster.

 

What I'm wondering is that Maya has different Python versions for each version, so I don't know if I have to compile in different environments.

 

When distributing MELs, I don't have to worry too much about Maya version differences, but for plugins created by compiling Python, I have to worry about Maya versions, right? 

 

Should I use anacondaPrompt etc. to create a Python 2.7 .pyc file?

Or is there a way to compile Python scripts using only Maya without using an external environment such as anaconda? If anyone is familiar with it, please let me know.

How to compile a Python script for Maya and create a .pyc file

I'm writing a Python script for Maya. I would like to compile and distribute it to make the code a little more confidential and to make it a little faster.

 

What I'm wondering is that Maya has different Python versions for each version, so I don't know if I have to compile in different environments.

 

When distributing MELs, I don't have to worry too much about Maya version differences, but for plugins created by compiling Python, I have to worry about Maya versions, right? 

 

Should I use anacondaPrompt etc. to create a Python 2.7 .pyc file?

Or is there a way to compile Python scripts using only Maya without using an external environment such as anaconda? If anyone is familiar with it, please let me know.

Labels (2)
3 REPLIES 3
Message 2 of 4
negow
in reply to: YASUSHI_EMOTO

negow
Advocate
Advocate
Accepted solution

.pyc files are generated on first import of your Python .py file, just import it from Maya or mayapy and it'll be created in a way that's compatible with Maya; you won't need Anaconda or an external Python, in fact you should probably avoid it as it may differ from the version shipped with Maya.

 

As for which versions the .pyc runs with, the thing to keep in mind is which major and possibly minor version of Python Maya ships with; which as Maya 2015-2020 is Python 2.7. For Maya 2021 you'll likely need a separate .pyc.

 

Regarding performance and confidentiality, the only time savings you could hope for is time-to-import, and any .pyc can be turned back into a .py file using something like Decompyle so best not to store your deepest secrets in there.

.pyc files are generated on first import of your Python .py file, just import it from Maya or mayapy and it'll be created in a way that's compatible with Maya; you won't need Anaconda or an external Python, in fact you should probably avoid it as it may differ from the version shipped with Maya.

 

As for which versions the .pyc runs with, the thing to keep in mind is which major and possibly minor version of Python Maya ships with; which as Maya 2015-2020 is Python 2.7. For Maya 2021 you'll likely need a separate .pyc.

 

Regarding performance and confidentiality, the only time savings you could hope for is time-to-import, and any .pyc can be turned back into a .py file using something like Decompyle so best not to store your deepest secrets in there.

Message 3 of 4
stuzzz
in reply to: negow

stuzzz
Collaborator
Collaborator

What python version is used within Maya 2021?

0 Likes

What python version is used within Maya 2021?

Message 4 of 4
YASUSHI_EMOTO
in reply to: negow

YASUSHI_EMOTO
Enthusiast
Enthusiast

Thank you very much. This answer was helpful. I usually develop with MEL, but I'm worried that the source code can be read by anyone. C ++ is difficult for beginners like me. I've heard that 3dsMax has a simple scripting method for obfuscation, but I hope Autodesk can offer some new solutions in Maya as well.

Thank you very much. This answer was helpful. I usually develop with MEL, but I'm worried that the source code can be read by anyone. C ++ is difficult for beginners like me. I've heard that 3dsMax has a simple scripting method for obfuscation, but I hope Autodesk can offer some new solutions in Maya as well.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report