Setting up PyCharm for use with Maya 2013

All,

I wanted to post some instructions on how to get PyCharm auto-completing and remote debugging code with Maya 2013. Since everyone’s work environment is slightly different, note that there’s probably a few different ways to get this done. The following is how my stuff is currently set up:


=================================
PyCharm 2.6.2 Setup for Maya 2013
=================================

Prerequisites:
--------------

    * Your OS is windows 7 (Assumed to be x64)
    * Download and install PyCharm:  http://www.jetbrains.com/pycharm/download/
    * AutoDesk Maya is installed
    
Instructions:
-------------

    1. Create a symbolic link to mayapy.exe
    
        * Open a command prompt with admin rights:
            Start > All Programs > Accessories > right click on Command Prompt > Run as Administrator > Click [Yes] at UAC Dialog popup
            
        * Navigate to Maya's bin directory:
            cd "c:\Program Files\Autodesk\Maya2013\bin"
        
        * Make a symbolic link from mayapy.exe to python.exe (This essentially creates a renamed exe shortcut)
          You should see, "sybmolic link created for python.exe <<==>> mayapy.exe" if successful:
            mklink python.exe mayapy.exe
          
    2. Configure PyCharm Maya Interpreter
    
        * Open PyCharm
        
        * Open the settings window
            File -> Settings...
            
        * Add our python.exe symlink as a python interpreter:
            * Navigate to Settings > Template Project Settings > Project Interpreter > Python Interpreter
            * click the [Add] button (plus icon) on the top far right
            * select "Local..." from the Select Interpreter Path dialog
            * select our "python.exe" symlink found at "C:\Program Files\Autodesk\Maya2013\bin\python.exe" from the selection dialog
            * hit the [OK] button and wait while PyCharm updates skeletons
            
            Leave this window up, don't close it!
        
        * Configure the Paths for our newly added interpreter:
            * With our newly added interpreter selected in the top pane, click on the _Paths_ tab in the bottom pane of the Python Interpreters window
            * Add path to AutoDesk provided stub files (This seemed to fix completion issues I was having):
                * Click the [Add] button (plus icon) on the top right of the _Paths_ pane
                * Navigate to and select "C:\Program Files\Autodesk\Maya2013\devkit\other\pymel\extras\completion\py" then click [OK] button
            * Remove Maya's site-packages entry (only if you added the stubs outlined above)
                * Select the entry for "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages"
                * Click the [Remove] button (minus icon)
            * Add path Jetbrains Helpers (for remote debugging)
                * Click the [Add] button (plus icon) on the top right of the _Paths_ pane
                * Navigate to and select "C:\Program Files (x86)\JetBrains\PyCharm 2.6.2\helpers" then click [OK] button
            * OPTIONAL: Add any other sys paths you wish to incorporate here using same add steps as above
        
        * Close PyCharm and Reopen it for paths to take affect
        
    3. Configure PyCharm Maya remote debugger
    
        * From the Run menu of PyCharm choose "Edit Configurations..."
        
        * Configure the Unnamed debugger which appears as follows:
        
            * Change Name field from "Unnamed" to "Maya 2013"  (This value names the debugging process, feel free to choose any name)
            * Change port from "0" to "7720"  (This number determines the port which traffics communication, feel free to use another port)
            * Check [x] Check no other instances are running
            * OPTIONAL:  Uncheck [ ] Redirect output to console  (to prevent output redirection from Maya)
            * OPTIONAL:  Uncheck [ ] Suspend after connect  (to only pause at a breakpoint)
            
            Note: settings in this window affect the code necessary to trip the remote debugger, displayed in sections 2 and 3.  Be sure
                  to write it down (or re-open this configuration window later to retrieve it later)
                  
    4. Remote Debugging from Maya
    
        * In PyCharm:
            * Select the "Maya 2013" Remote Debug profile from the Run/Debug dropdown just below the main menubar
            * Click the green debug icon next to the dropdown to start PyCharm's server
            * You will see a debug console appear below the main code window indicating the server is awaiting a connection
            * Load the code you wish to step through, and ensure there's a breakpoint set somewhere within the code
            * Paste the server configuration code from step 3's note into your code somewhere before your breakpoint and save the file.
            
        * In Maya:
            * Ensure that "C:\Program Files (x86)\JetBrains\PyCharm 2.6.2\helpers" is part of your sys.path  (there are numerous ways to do this)
            
                pydev_path = r'C:\Program Files (x86)\JetBrains\PyCharm 2.6.2\helpers'
                if not pydev_path in sys.path:
                    sys.path.append(pydev_path)
            
            * Import your and execute the code to remote debug.  If all goes well, PyCharm should hold the code at your breakpoint, allowing
              you to navigate the code using the bottom Debugger pane

Here’s some images to go along with these instructions. At some point, I’ll put these on my site in a more organized manner. Hope they help:

-csa

Thanks! If I ever get the cash to get pyCharm I will definitely use this.

Based on a glowing recommendation, I got ahead of myself and purchased a copy of PyCharm… without testing it with Maya first naturally.

I’ve then followed this guide to the letter on a few different machines, in Maya 2013 x64/2013.5 x64 and using a range of different ports. For remote debugging every time I try to connect, Maya just hangs indefinitely. Did anyone run into this? Found a fix?

This along with the Copy/paste thing, has me itching to just boot up wing, but I feel I should somehow get my moneys worth :slight_smile:

I’m on PyCharm 2.7.3

Cheers,
Sune

Here is a capture of my setup attempt:

I must be missing something because my bin folder does not contain the python.exe file :confused:

It’s in step one of the guide, making a symbolic link.

I’ve tried remote debugging Maya/MotionBuilder on a few computers now. As it works a “Charm” on some, but not at all on others, I’m thinking my troubles are down to Security Software getting in the way of remote debug. I’m going to call IT and will hopefully have it working in about 6 months :slight_smile:

3 month in and still no solution from IT (see I told you). However something must have changed (I did change to the same port as wing debug works on), so now stuff works… Not going to look further into it why now, just happy it works :slight_smile: I’m really (really) loving my PyCharm.

Hi Sune,

You mention MotionBuilder … how did you handle it given that there is no mayapy.exe equivalent in MoBu?

EDIT:

Nevermind, figured things out.

Just jumped straight down to the Debugger Configuration setup, configured it, and then made sure that MotionBuilder was using the pydev in PyCharm (e.g. adding this to the sys.path in Mobu: r"C:\Program Files (x86)\JetBrains\PyCharm 3.0\pycharm-debug.egg").

Hi csa3d. Thank you for your useful information.

I’m trying to debug maya python using PyCharm3.0 pro by reading your great material. (I understand your info is for PyCharm2.6.2)
I probably finished the above setup correctly. But when I execute my python file via Maya scripted editor like the last step, I encountered the following error…
Of course, I already added some breakpoints into my python code on PyCharm3.0 pro.

ValueError: invalid literal for int() with base 10: ‘c:/temp/test_debug.py’

line = int(line)

File “C:/temp/python/lib/pydev/pydevd.py”, line 609, in processNetCommand

Traceback (most recent call last):

pydev debugger: warning: trying to add breakpoint to file that does not exist: python-line (will have no effect)

pydev debugger: Unable to find real location for: python-line


Is there anyone who can debug maya python on PyCharm3.0 Pro?
If so, I would like to know the some clue or tips to finish the setup for PyCharm3.0 Pro.

According to the JetBrains offical announce, PyCharm3.0 already suports maya remote debug.
But I can’t find the tutorial or the documentation… Is there some official information ?
http://confluence.jetbrains.com/display/PYH/PyCharm+3.0+Roadmap

Thanks in advance.

[QUOTE=dragonboy765;22776]Hi csa3d. Thank you for your useful information.

I’m trying to debug maya python using PyCharm3.0 pro by reading your great material. (I understand your info is for PyCharm2.6.2)
I probably finished the above setup correctly. But when I execute my python file via Maya scripted editor like the last step, I encountered the following error…
Of course, I already added some breakpoints into my python code on PyCharm3.0 pro.

ValueError: invalid literal for int() with base 10: ‘c:/temp/test_debug.py’

line = int(line)

File “C:/temp/python/lib/pydev/pydevd.py”, line 609, in processNetCommand

Traceback (most recent call last):

pydev debugger: warning: trying to add breakpoint to file that does not exist: python-line (will have no effect)

pydev debugger: Unable to find real location for: python-line


Is there anyone who can debug maya python on PyCharm3.0 Pro?
If so, I would like to know the some clue or tips to finish the setup for PyCharm3.0 Pro.

According to the JetBrains offical announce, PyCharm3.0 already suports maya remote debug.
But I can’t find the tutorial or the documentation… Is there some official information ?
http://confluence.jetbrains.com/display/PYH/PyCharm+3.0+Roadmap

Thanks in advance.[/QUOTE]

With pycharm 3.0 you no longer really need to follow this process for the most part. You can just point the interpreter to mayapy.exe in the bin folder and you should be good to go. This is how I currently have my project interpreter setup in pycharm

Hi Jredd. Thank you for your reply. But I don’t understand your current situation. you mean, you already can do Maya remote debugging on PyCharm3.0?
I asked the same question to Jetbrain which is the developer of Pycharm. However, they answered that “Maya support will be in a separate plugin that hasn’t been released yet. sorry for the confusion”. So I guess that we can’t do the remote debugging on Pycharm3.0 since Jetbrain will release the separate plugin.

So I’m curious about the specific method to setup the remote debugging without the above plugin, if you can debug even now.
Thanks in advance.

[QUOTE=dragonboy765;22940]Hi Jredd. Thank you for your reply. But I don’t understand your current situation. you mean, you already can do Maya remote debugging on PyCharm3.0?
I asked the same question to Jetbrain which is the developer of Pycharm. However, they answered that “Maya support will be in a separate plugin that hasn’t been released yet. sorry for the confusion”. So I guess that we can’t do the remote debugging on Pycharm3.0 since Jetbrain will release the separate plugin.

So I’m curious about the specific method to setup the remote debugging without the above plugin, if you can debug even now.
Thanks in advance.[/QUOTE]

Ah dragon sorry I wasn’t thinking when I posted last. Yes you can’t debug with the current pycharm without doing the above methods but It’s easier now to incorporate Maya’s exe of python so you can easily call on Maya specific methods without having to jump through the loops you use to have to do in the above tutorial.

PyCharm peeps said this Maya functionality would be added in January this year, then they said with 3.1… I still don’t see this plugin, any news?

[Thread bump]

If you try to run unit tests in Pycharm using MayaPy as you’re intepreter, the test runner fails because PyCharm wants to import the os module directly and it can’t get at the copy of the OS module in <MAYA>/Lib/python27.zip .

If you either unzip the library as in this example, or have a separate python install on your machine with the same version as your maya python, you can remove the path from your interpreter setup in pyCharm and then add a link to the location of your (unzipped) standard library:


You should be able to run the tests etc no problem.

Note that in the link above the guy is removing the zip file and the /Lib folder. In my example I was able to leave /Lib intact so the only substitution is the standard library location. There may be wierd interactions down the road - some packages use the location of os.py to figure out where the interpreter is, which is going to be wrong in this case - but I haven’t seen anything yet.

Not having much luck with this, i can get it to connect but then get this:

import pydevd
pydevd.settrace('localhost', port=7720, stdoutToServer=True, stderrToServer=True)
# -------------------------------------------------------------------------------
# pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)
# pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.
# pydev debugger: Related bug: http://bugs.python.org/issue1666807
# -------------------------------------------------------------------------------
# pydev debugger: Unable to find real location for: C:\\Program Files (x86)\\JetBrains\\PyCharm 3.4.1\\pycharm-debug.egg\pydevd.py
# pydev debugger: Unable to find real location for: C:\Program Files\Autodesk\Maya2014\bin\python27.zip	hreading.py
# pydev debugger: Unable to find real location for: C:\\Program Files (x86)\\JetBrains\\PyCharm 3.4.1\\pycharm-debug.egg\pydevd_additional_thread_info.py
# pydev debugger: Unable to find real location for: C:\\Program Files (x86)\\JetBrains\\PyCharm 3.4.1\\pycharm-debug.egg\pydevd_comm.py
# pydev debugger: Unable to find real location for: <maya console>
# pydev debugger: Unable to find real location for: C:\\Program Files (x86)\\JetBrains\\PyCharm 3.4.1\\pycharm-debug.egg\pydevd_tracing.py

I had to append ‘C:\Program Files (x86)\JetBrains\PyCharm 3.4.1\pycharm-debug.egg’ instead of /helpers to get this to work, because helpers just kept giving me a ‘no module named pydevd’ error…

those messages are not exactly harmless but you should be able to work with them. Have you tried stepping through code with the connection on? The messages will only interfere with your ability to step into standard lib code or pydevd itself, which are rarely necessary

I get the same errors plus a bunch of other messages when starting the debug connection and executing even simple one line scripts. until after failing on some openMaya packages (which I don’t even import or do anything else with) it halts maya entirely until I disconnect pycharm.



Has anyone done this more recently and had the hanging issue? There was never a posted solution above.

Actually, is there anyone using PyCharm in Maya 2016 now and did you do anything different from this setup?

[QUOTE=Sariel;29048]Has anyone done this more recently and had the hanging issue? There was never a posted solution above.

Actually, is there anyone using PyCharm in Maya 2016 now and did you do anything different from this setup?[/QUOTE]

I know it’s been a long time since this question was asked but may still be useful to someone.

On my side (Maya2015) I noticed that when adding the following code to my userSetup.py maya would hang until I launched the debugger in pycharm. Once the debugger is attached to maya, maya would continue to run nicely.

import pydevd
pydevd.settrace('localhost', port=7720, suspend=False)

Oh and one more thing. Will be obvious to most of you guys but for the others, once the debugger breaks on a break point you set, Maya will freeze until you say to the debugger to continue or close it.