Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Maya 2022 with Python 3.7 #25

Open
1fth3n3ls3 opened this issue Apr 1, 2021 · 23 comments
Open

Add support for Maya 2022 with Python 3.7 #25

1fth3n3ls3 opened this issue Apr 1, 2021 · 23 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@1fth3n3ls3
Copy link

1fth3n3ls3 commented Apr 1, 2021

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
Copy link

Rourker commented Apr 2, 2021

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

@artbycrunk artbycrunk self-assigned this Apr 2, 2021
@artbycrunk artbycrunk added enhancement New feature or request good first issue Good for newcomers labels Apr 2, 2021
@artbycrunk
Copy link
Owner

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

@Rourker
Copy link

Rourker commented Apr 3, 2021

Thanks a lot

@a690089735
Copy link

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
Copy link
Owner

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

@artbycrunk
Copy link
Owner

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
Copy link

ypypjay commented Apr 21, 2021

@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
Copy link

ypypjay commented Apr 21, 2021

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

@ZachGray
Copy link

ZachGray commented Jul 30, 2021

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

@CraigMason
Copy link

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
Copy link

Ruka1998 commented Oct 14, 2021

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
Copy link

Leo-Vitalis commented Oct 16, 2021

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
Copy link

NicTanghe commented Oct 29, 2021

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
Copy link
Owner

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
Copy link
Owner

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

@ZachGray
Copy link

ZachGray commented Nov 1, 2021

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
Copy link
Owner

@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
Copy link

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

This was referenced Jun 7, 2022
@mrbmp33
Copy link

mrbmp33 commented Jan 25, 2023

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
Copy link

kristafervale commented Feb 25, 2023

+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
Copy link

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

@AgastyaPatel
Copy link

AgastyaPatel commented Jan 8, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests