Env Setup – Part 1.2 – Connect PyCharm To Maya

In order for our dev environment to be complete, we need to have PyCharm debug code in Maya. This is something that you ‘could’ live without. I recommend you have this done because it will make your life much easier.

I like to use MayaCharm. It’s a PyCharm plugin that has a Python interpreter for PyCharm that emulates Maya. Also, it can connect directly with Maya to use PyCharm as a debugger. It’s all kinds of wonderful.

If you are interested on the Github page, or want to see the docs, here they are MayaCharm documentation.

For the quick and easy install, it’s best if you do it from inside PyCharm.

Go to File / Settings …

pyCharm_maya_connect_01

On the Search Bar, type “MayaCharm“. Only one plugin will come up. Install it and restart PyCharm.

You are not done yet. You still have to set up your Python interpreter for your current PyCharm project. So go back to your Settings Window ( File / Settings … ). Click on the “Project Interpreter” drop down, and select “Show All…

pyCharm_maya_connect_02

A new window appears. Here you need to point PyCharm to mayapy.exe (which is the Maya Python interpreter).

pyCharm_maya_connect_03
Click the “+” button
pyCharm_maya_connect_04
Select the System Interpreter on the left, and click on the “…” button.
pyCharm_maya_connect_05
Navigate to mayapy.exe in your Maya install folder

Click “OK” and you should now see the mayapy.exe interpreter added to your Project Interpreters Window:

pyCharm_maya_connect_06

Depending on your version of PyCharm, you might need to install the Python Packaging Tools. If it asks for it, do so.

At this point you need to restart PyCharm again. Even if you restarted it for the Python Packaging Tools, you need to restart anyway. If you don’t, the Active Maya SDK section of the Settings Window will be empty and you wont be able to continue. So

pyCharm_maya_connect_07

You now have to tell Maya to listen for incoming commands from PyCharm. So navigate to your userSetup.py file. This file is normally located here: “C:\Users\…user…\OneDrive\Documents\maya\2018\scripts

Open it and add these lines:

import maya.cmds as cmds

if not cmds.commandPort(':4434', query=True):
    cmds.commandPort(name=':4434')

Notice how the port name in the code is 4434, and the port in the MayaCharm Settings Window is also 4434. These number HAVE to match in order for the connection to work.

Alternatively, you could run these lines directly from the Script Editor in Maya if you wanted. This will work as well, but you will have to do it every time you open Maya. On the one hand, you don’t worry about Maya keeping the port open when you are not using PyCharm, and on the other, you have to run the command every time you want to debug with PyCharm. Ultimately, the choice is yours.

You are done with the Maya / PyCharm set up!

pyCharm_maya_connect_08

In the “Run” menu at the top of PyCharm, there are now 3 new lines. These will send the commands to Maya.

Try it out.

highlight a print command and watch it print in the Maya Script History.

I hope this worked out for you guys. If not, leave me a note with what problems you have and we will troubleshoot it together.

// Isoparm

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.