Having tried the remote debugging for a while, it is time to share my settings which works for the most recent versions of May and PyCharm, i.e., Maya 2016 and PyCharm 2016.1. Note that today is May 30, 2016.
Before everything, my using circumstances. There are two machines I am using, one is my home desktop running on Windows 7. Why Windows? because I stubbornly believe clicking mouse is faster than typing keyboard in terms of both entertainment application and debugging programming codes. Another workstation machine, located in my lab, is running a ubuntu 14.04 with Xfce GUI desktop installed so that I can run Maya. PyCharm 2016.1 is installed on my home desktop while Maya is not for license issue. Maya is installed on my lab workstation while PyCharm is not (don’t ask me why, I know PyCharm is today’s best python IDE but I am not the boss). So, what I want is to debug python codes running in Maya on the ubuntu machine in the lab, using the PyCharm on Windows running at home. Now I am sitting in the lab, using ubuntu’s Remmina Remote Desktop to show the desktop of my home computer on the right screen, while using Maya locally on the left screen. See, remote debugging is not necessarily motivated by long distance, but sometimes by separate working environment. An SSH tool (Bitvise SSH Client, GUI again) is running on the Windows to copy files between two machines.
On the Remote Debugger Server side (or home, Windows), in the Python Remote Debug Configuration, you need to fill in the IP address of the PyCharm machine and port number of the debug server which is 7720. It is worth noting that in most routers at home, firewall is turned on by default. You need to set up the router so that PyCharm’s remote debugging service can be exposed to the outer internet world. It seems that different ISP and router manufacture has different settings. Below is my router setting so you can know how to configure it if you happen to be an AT&T customer.
From the above settings you can also know how to connect to your home Windows machine by remote desktop. Path mappings is a must. Here “local path” means the path on the Python machine (or home, Windows, which is actually a remote machine one hour from me), say, C:/home_machine, while the Remote Path is the ubuntu path of the machine sitting quietly besides my foot, say, /home/lab_workstation/. Note that the path are the folders containing the python script you are about to debug. Leaving other options unchanged, the Python Remote Debug Configuration window looks like below:
The three steps required in the above configuration window is what we should do on Maya machine. The PyCharm side config in step 4 in original post was written in a very confusing way. The two lines
pydevd.settrace('your.ip.address.0', port=7720, stdoutToServer=True, stderrToServer=True)
should be added at the beginning of the PyCharm code to be debugged. The python code to be debugged will be run inside Maya Script Editor, so you don’t have to install some packages needed on the Python machine, say, the notorious scipy that cannot be installed directly in PyCharm, as an added advantage of remote debugging. You should make sure that the source code in Maya machine and in Python IDE machine are identical, otherwise the breakpoint will not pause at the line you expected.
Now let’s go to the Maya side (Lab workstation, ubuntu). It is only a 45-degree rotation of my head. As postulated in the Python Remote Debug Configuration window, you have to make sure pydevd is in the search path so that it can be imported correctly. In ubuntu, this can be done by the following command:
pip install --user pydevd
This command will install the required pydevd module in charge of communication between two machines into ubuntu, or Maya machine and set the path automatically. Have you noticed the --user flag? It asks pip to install the module on your local folder (./local/lib/python2.7/site-packages) because I have no write access to the system folders like /usr/bin. Working area! Sign~
In my case, we don’t need to worry about the archive pycharm-debug.egg in ubuntu required by the first step because the client (Maya) and the debugging server (PyCharm) are two separate machines, as explained in Pycharm’s doc; the above pip command handles everything. But we have to set it if they are in the same machine. After installing pydevd, add the above two lines in Maya’s Script Editor, don’t run, because we haven’t yet start the PyCharm’s remote debugging server running on my home Windows. So now let start it through Remmina remote desktop (I assume you have properly configured it. It is not the topic of this thread). Here , I have already copied the source files in both folders involved in the mapping settings. Make sure the “Maya 2016” debug setting is selected and click the bug icon. We are given the following prompts:
Waiting for process connection…
Don’t forget to set breakpoints in the python source in the PyCharm IDE. But it’s OK to forget it because PyCharm will be considerate enough to put the execution at the first line after the two magic lines mentioned above. Now in Script Editor of Maya , type in the function or module you want to debug, say, import myModule or myModule.test(), etc. After clicking the run icon in Maya, Maya will not respond any more, because the control is transferred to the PyCharm’s debugger. You should see the breakpoint is highlighted in blue and you are now good to do debugging work. Sometimes a tab in Python may occur; this is because the execution is in some code that does not have source available, usually system codes, just resume running by click the green “Resume Program (F9)” arrow icon to continue. Here is an important note: if you use import myModule to run the code to be debugged, it will work only for the first time. If you make some changes to your code and want to debug it again using import, the breakpoint will not be triggered because the code is cached and therefore not executed at all! As a result, you should use reload(myModule) to forcibly run the python code and have it captured by breakpoints set in remote debugger. PS: the parameter passed to reload function is the (already loaded) module name, not file name, so no quotation marks, no “.py” extension.
It is often the case you want to stop debugging and modify the code. Don’t stop the debugger server by, say, clicking the red square icon or “Rerun Maya 2016” icon. This would make Maya never be able to connect to PyCharm remote debugger, before you have to restart Maya to have it connect to PyCharm again. What you should do is to run in Maya this special code:
After executing this line, you are free to change your code in PyCharm, copy it to lab folder (for synchronization purpose) and reconnect to the debugger server for further bug-finding work.
My workflow is not necessarily the best for all cases. For example, someone in previous replies suggested using remote python interpreter. But that is not possible in my case because Maya is accessible from my home Windows desktop through two SSHes: one to log into an outer server of my univ, and a second ssh is needed to login the internal lab workstation. I don’t know how to configure SSH Credentials in “Configure Remote Python Interpreter” window for my situation. So why not VPN? Com’on, I will lose connection to my home Windows immediately after VPN is started; you know why. I don’t want to spend an hour to go back home to reboot my home machine and another hour to return to lab to continue work. I would be greatly appreciated it if you can tell me how to work around these issues so that I can work at home
OK, that’s it. Enjoy!