artbycrunk / vscode-maya

A Visual Studio Code extension with support for coding for Maya.
MIT License
45 stars 11 forks source link

Add support for Maya 2022 with Python 3.7 #25

Open 1fth3n3ls3 opened 3 years ago

1fth3n3ls3 commented 3 years ago

When I try to execute Send Python Code to Maya I get this error.

`

# Exception happened during processing of request from# ---------------------------------------- # ---------------------------------------- ('127.0.0.1', 63876) # Traceback (most recent call last): # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 316, in _handle_request_noblock self.process_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 347, in process_request self.finish_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 720, in __init__ self.handle() # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\maya\app\general\CommandPort.py", line 134, in handle self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write self._sock.sendall(b) # TypeError: a bytes-like object is required, not 'str'
`
Rourker commented 3 years ago

Yeah, this would be a much needed update for me, thanks!

artbycrunk commented 3 years ago

Thanks for reporting, let me have a look and get back

Rourker commented 3 years ago

Thanks a lot

a690089735 commented 3 years ago

me too # Traceback (most recent call last): # ---------------------------------------- # ---------------------------------------- # Exception happened during processing of request from ('127.0.0.1', 11353) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 316, in _handle_request_noblock self.process_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 347, in process_request self.finish_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 720, in init self.handle() # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\maya\app\general\CommandPort.py", line 134, in handle self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write self._sock.sendall(b) # TypeError: a bytes-like object is required, not 'str'

artbycrunk commented 3 years ago

Apologies this is taking a while, just got my hands on a copy of 2022. WIll have a fix out soon.

artbycrunk commented 3 years ago

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"

Note that you need to do this in a new maya session, as you cannot modify the ports you have already opened.

There is a bug in this file, that is causing the issue with echo output. C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799

ypypjay commented 3 years ago

@artbycrunk I think there is another improvement to make. execfile() is replaced by exec() in python 3,and it's still execfile() being used in MayaCode extension.

ypypjay commented 3 years ago

Sorry that I can't make a pull request because I'm still newbie in programming and afraid to mess your code up.

ZachGray commented 3 years ago

Love this extension, would love an update to execfile() for 3.7/2022 if it's simple enough.

CraigMason commented 3 years ago

Just to confirm, this does not work with a fresh install of Maya 2022 with the same error described above:

# Error: line 1: NameError: file <maya console> line 1: name 'execfile' is not defined #

Ruka1998 commented 3 years ago

Just to confirm, this does not work with a fresh install of Maya 2022 with the same error described above:

# Error: line 1: NameError: file <maya console> line 1: name 'execfile' is not defined #

@CraigMason You can try this one https://github.com/DubiousLatchkey/vscode-maya/tree/2022-3.7-support Pack the source code to vsix installer and reinstall will fix this issue.

Leo-Vitalis commented 3 years ago

Just to confirm, this does not work with a fresh install of Maya 2022 with the same error described above:

# Error: line 1: NameError: file <maya console> line 1: name 'execfile' is not defined #

You can change the execfile line to:

cmd = python("exec(open('${posixPath}').read())");

extension.js file should be located at C:\Users\name\.vscode\extensions\saviof.mayacode-1.4.0\out There is a copy of the file in src folder, I changed the line in both.

NicTanghe commented 3 years ago

Hello, I'm dying over here being forced to use multiple overcomplicated IDE's.

Can @artbycrunk b a hero do all this in the main branch and ad a toggle option to the config? I'm also not versed with pull requests etc.

EDIT: thx 4 the quick reponse

artbycrunk commented 3 years ago

Apologies this took a while to get to,

Please update to the latest version of extension 1.5.0

Note that there is a new setting required to be enabled when using Maya 2022. image

artbycrunk commented 3 years ago

@NicTanghe @Vitali-Iakovlev @Ruka1998 @CraigMason @ZachGray @ypypjay @a690089735 @Rourker @1fth3n3ls3 hope its working for everyone now.

ZachGray commented 3 years ago

Thanks for the update!

~~Works great the first time, but sending subsequent snippets seems to break the port. (using 7010 because of a port conflict) Maya 2022.1 x64 Let me know if I can provide better info or help debug. Using in conjunction with the MayaPy extension which has a dependency on MayaCode~~

Sorry about that, missed the post about commandPort -name "localhost:7001" -sourceType "mel"

Note that you need to do this in a new maya session, as you cannot modify the ports you have already opened.

There is a bug in this file, that is causing the issue with echo output. C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799

This is the same error at the top of the thread. Curious why it might be changing after first execution.

# ----------------------------------------
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write
    self._sock.sendall(b)
# TypeError: a bytes-like object is required, not 'str'
# ----------------------------------------
artbycrunk commented 3 years ago

@ZachGray I am not able to reproduce this, all I can think of is that one of your snippets is using commandPort with -echoOutput that should be the only reason to get a traceback with socketserver.py", line 799

Fadeevone commented 2 years ago

Hi guys, for everyone who still have issues with socketserver and other stuff from this thread, first - check that you had fixed this line commandPort -name "localhost:7001" -sourceType "mel"; second - reinstall this plugin, and also reinstall MayaPy plugin if you have, because they have some dependencies. I don't know why, but it works for me.

Thanks everyone, btw

mrbmp33 commented 1 year ago

Hi I have seen this post in the autodesk site that talks about this issue in particular.

It seems like from Python2.7 to 3.7 maya expects a command to be passed as a bytes instead of strings. The link includes possible solutions so feel free to give it a look :)

kristafervale commented 1 year ago

+1 what @mrbmp33 said

Not to double post but here's what I found debugging this issue in Maya 2023:

I have an update on what I found after doing a little digging around in Maya's source scripts.

in the file F:\Program Files\Autodesk\Maya2023\Python\Lib\site-packages\maya\app\general\CommandPort.py

On line 134, as an experiment I changed it

from: self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term)

to:

self.server.commandMessageQueue.get() + self.resp_term
#self.wfile.write()

effectively telling it to go ahead and execute the message in the commandMessageQueue but don't do the self.wfile.write().

And wouldn't you know it, after reloading Maya everything worked as expected.

print("hello world") outputted to the output just fine,

and cmds.sphere(r=1,n="hell_world_sphere") created a nurbs sphere called hello_world_spehre as expected.

I'm not sure what you will have to do to update your extension, obviously we can't all edit our Maya source code to make this work, but hopefully this will lead you in the right direction?

wesschneider commented 1 year ago

@kristafervale Thanks for your input... you save the day :)

AgastyaPatel commented 10 months ago

Ref: Check this for solving. This solved the issue for me


import maya.cmds as cmds
cmds.commandPort(name="127.0.0.1:7002", stp="python")
cmds.commandPort(name="127.0.0.1:7001", stp="mel")`
zhalice2011 commented 8 months ago

To debug Above Maya 2022 Python code in VS Code, you can use the "Debugger for Maya" extension available here: Debugger for Maya

For guidance on how to use it, check out this video tutorial: Video Tutorial