Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to configure Visual Studio Code for Maya 2019?

How to configure Visual Studio Code for Maya 2019?

g2m.agent
Collaborator Collaborator
13,953 Views
8 Replies
Message 1 of 9

How to configure Visual Studio Code for Maya 2019?

g2m.agent
Collaborator
Collaborator

I want to write some script with vs code, but it kept reminding me: 

Unable to import 'maya.cmds' pylint(import-error)

why??

Code_6toIvfuArL.pngCode_cfdm3fFn8e.pngCode_FbGAdXbU7P.png

I spent hours searching the Internet and still had no answer ...

 

Windows 10 x64

Maya 2019 + devkit

Anaconda 2019.03 x64 (python2.7)

Visual Studio Code 1.35 (extensions: Python, MayaCode)

 

Accepted solutions (1)
13,954 Views
8 Replies
Replies (8)
Message 2 of 9

Boon_in_Oz
Participant
Participant

I have exactly the same problem, currently in Maya 2018. Here's a little more info from my case:

If I do ctrl+shift+p, "Python:Select Interpreter" and set it to mayapy.exe, Pylint appears not to work at all. No errors are underlined.

If I set it to a different python.exe (Python 2.7) it works, but it complains about all my Maya (and MaxPlus and pymxs in my Max scripts) imports.

 

Autocomplete works perfectly for me too. The problem is only with Pylint.

 

I have also tried

PYTHONPATH=C:\\Program Files\\Autodesk\\Maya2018\\Python\\Lib\\site-packages; ...

in an env file, pointed to by python.envFile in settings.json, but unfortunately I haven't found a way to verify that works at all.

Message 3 of 9

Anonymous
Not applicable

Did either of you sort this out? I also am exploring using VSC for Maya 2018...

0 Likes
Message 4 of 9

g2m.agent
Collaborator
Collaborator
Accepted solution

Yes, I found a solution!

You need to install MayaCode and MayaPy two plug-ins, and then execute this mel command in Maya:

 

commandPort -n "localhost:7001" -stp "mel" -echoOutput;

 

Finally, right-click in vs code->Send Python Code to Maya!

 
Message 5 of 9

Abdelmolkmounir1917
Observer
Observer
0 Likes
Message 6 of 9

moiamy
Collaborator
Collaborator

Hi

Is there an update for Maya 2022 ? I have established communication between VSC and Maya 2022 with :

 

commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;

 

But when I execute "Send Python code to Maya" I got this error :

 

moiamy_0-1669144449290.png

 

Message 7 of 9

denis.chikalyuk
Explorer
Explorer

Hey, fellas! Just in case someone will search help for Maya 2022 solution, here it is.

Author of that extension suggested  next:

ok so one quick solution is to avoid using the -echoOutput when you init the commandPort

so instead of this

commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;

you can run just this

commandPort -name "localhost:7001" -sourceType "mel"

 and it works for me in latest Maya 2022. 

Cheers!😉

Message 8 of 9

jaranalDB9F6
Explorer
Explorer

Removing echoOutput from the commandPort command in 2022 worked for me with sending Python over the commandPort, but for some reason MEL scripts always give a syntax error

0 Likes
Message 9 of 9

brian_mckee
Participant
Participant

I'm getting a similar error message:

brian_mckee_0-1722967034040.png

I have tried both:

commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;
commandPort -name "localhost:7001" -sourceType "mel";

Maya 2023. Any Suggestions?
0 Likes