Env Setup – Part 1.0 – Software Needed For Maya/Python Development

First off, we need to have an appropriate environment. In order for us to be set up for success, we need to well… set ourselves up for success. I spent years using the “wrong” IDE. I fought with it, I yelled at it, i even re installed it a few times thinking it would fix my problems. For the longest time i was convinced that the problem was me, not the software. While there are many right answers to the question of the “Best IDE for Python” questions, there are definitely some wrong ones. So don’t be like me, pick a better one.

Here is the list of software we need. Some of it costs money… well it all costs money, but some of it can be used in trial, education, or limited versions. I will attempt to have an accessible environment during this project, so we can all speak the same language.

  1. Maya. Well sure, this is a given, but I had to put it in here. The software is not exactly cheap, but there are some things you can do. If you are a student enrolled in a school, you probably have access to an education version (that one will do nicely). You can also try out the software for 30 days (we probably wont be finished by then, but 30 days should be enough to figure out if you want to continue).
  2. Python 2.7. Unfortunately, Autodesk has not moved on from Python 2.x to 3.x. This means that we need to do our work in an older version of Python. Since Autodesk is pretty much a monopoly when it comes to rigging, then we must make do. Make sure you download 2.7.x, and not 3.x.
  3. PyCharm. This is my go-to IDE for Python. It integrates nicely with Maya and with Github.
  4. Sublime Text. Why have 2 IDEs? Well, there are some nice things about having a light weight text editor that is fully featured. I use it quite a bit. If you are on a  tight budget, you can skip this one.
  5. Github account. I will share all the code written for this project in Github, so it will be helpful to have an account so you can follow along. To setup Git, follow these instructions: Set Up Git.

OK, now go install all the software and come back, I’ll wait.

// Isoparm

Next: Connect Pycharm and Github

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

Env Setup – Part 1.1 – Connect PyCharm And Github

Lets setup PyCharm / Github.

You need a Github account, so make one.

Make a new Github Repository. The project I will be starting out using is this one: https://github.com/isoparms/dis.shared. I recommend you create a similar one.

github_newRepo
github_newRepo_options

Yay, you have a repository! Now we will clone it to your system.

Open GitBash (it got installed when you installed Git).

this is the clone command:

git clone https://github.com/isoparms/dis.shared C:\code_folder\disorder_project\shared

Once cloned, you can pull (get latest from Github) with this command:

cd C:\code_folder\disorder_project\shared
git pull

Alright, you have your repository set up. Now we move to PyCharm.

Make a File \ New Project

Use the same folder as the one you used for your repository.

Set up Git: File \ Settings

pyCharm_git_connect_01
pyCharm_git_connect_02

Cool, we are almost done. Now make a change, add a file, etc. Then press Ctrl + K. This is how you commit or check in, so memorize it.

pyCharm_git_connect_03

PyCharm will prompt you for your account and password. Make sure you make your settings global.

Now you are done.

Make sure you make all changes repository through PyCharm. Add, remove, edit, and even copy and paste files using PyCharm. That way, Github will know what you are doing at all times, so all you have to do, is commit every now and then.

Enjoy!

//Isoparm

Next: Connect PyCharm To Maya