Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Anyone get this invalid syntax issue when using Python 3 of Maya 2022?

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
Hai__Nguyen
45164 Views, 24 Replies

Anyone get this invalid syntax issue when using Python 3 of Maya 2022?

Hai__Nguyen
Participant
Participant

I got a tool I developed myself, which is still used okay in 2019 version of Maya. But when I updated to 2022 version, suddenly I couldn't use it anymore, the script editor said:

# Error: SyntaxError: file C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py line 142: invalid syntax # 

 

I designed it in a class way and called it like this in the Python tab:

 

import scenePublisher; reload(scenePublisher)

sc = scenePublisher.ScenePublisher(windowID = 'ScenePublisher', title = 'Scene Publisher', codec = 'film')

 

Anybody experienced this or know what this is I'll be really thankful!

 

 
0 Likes

Anyone get this invalid syntax issue when using Python 3 of Maya 2022?

I got a tool I developed myself, which is still used okay in 2019 version of Maya. But when I updated to 2022 version, suddenly I couldn't use it anymore, the script editor said:

# Error: SyntaxError: file C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py line 142: invalid syntax # 

 

I designed it in a class way and called it like this in the Python tab:

 

import scenePublisher; reload(scenePublisher)

sc = scenePublisher.ScenePublisher(windowID = 'ScenePublisher', title = 'Scene Publisher', codec = 'film')

 

Anybody experienced this or know what this is I'll be really thankful!

 

 
24 REPLIES 24
Message 2 of 25
zewt
in reply to: Hai__Nguyen

zewt
Collaborator
Collaborator

Do you have the whole stack trace?  The error probably has nothing to do with shiboken and there should be other lines in the stack trace.  shiboken does nasty things to Python's import and shows up in every import stack trace now.

 

"reload" isn't a builtin in Python 3, so you need to manually import it (from importlib import reload), but that wouldn't cause a syntax error.

 

0 Likes

Do you have the whole stack trace?  The error probably has nothing to do with shiboken and there should be other lines in the stack trace.  shiboken does nasty things to Python's import and shows up in every import stack trace now.

 

"reload" isn't a builtin in Python 3, so you need to manually import it (from importlib import reload), but that wouldn't cause a syntax error.

 

Message 3 of 25
Hai__Nguyen
in reply to: zewt

Hai__Nguyen
Participant
Participant

import scenePublisher

sc = scenePublisher.ScenePublisher(windowID = 'ScenePublisher', title = 'Scene Publisher', codec = 'film')
# Error: SyntaxError: file C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py line 142: invalid syntax #

 

This is everything I had when I ran the calling code and then the error shown up. Not sure if it's what you need 😕

0 Likes

import scenePublisher

sc = scenePublisher.ScenePublisher(windowID = 'ScenePublisher', title = 'Scene Publisher', codec = 'film')
# Error: SyntaxError: file C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py line 142: invalid syntax #

 

This is everything I had when I ran the calling code and then the error shown up. Not sure if it's what you need 😕

Message 4 of 25
zewt
in reply to: Hai__Nguyen

zewt
Collaborator
Collaborator
Accepted solution

Make sure you have History > Show Stack Trace enabled in the script editor.

 

Make sure you have History > Show Stack Trace enabled in the script editor.

 

Message 5 of 25
Hai__Nguyen
in reply to: zewt

Hai__Nguyen
Participant
Participant

Oooooooh I didn't see that coming! It said that it couldn't call the print function I wrote, because I wrote it as print b. This worked normally in Python 2.7 I guess because I did it all the time and it still worked. But as I learnt about Python 3.5 earlier, we gotta write it as print(b),  add in the parentheses. Thanks man!!!

0 Likes

Oooooooh I didn't see that coming! It said that it couldn't call the print function I wrote, because I wrote it as print b. This worked normally in Python 2.7 I guess because I did it all the time and it still worked. But as I learnt about Python 3.5 earlier, we gotta write it as print(b),  add in the parentheses. Thanks man!!!

Message 6 of 25
Anonymous
in reply to: Hai__Nguyen

Anonymous
Not applicable

I have the exact same error code but I don't understand the solution here? (I don't understand scripting) I'm following a well-known tutorial from someone who is competent, if you can explain it simply I'd really appreciate it. 

I have the exact same error code but I don't understand the solution here? (I don't understand scripting) I'm following a well-known tutorial from someone who is competent, if you can explain it simply I'd really appreciate it. 

Message 7 of 25
Hai__Nguyen
in reply to: Anonymous

Hai__Nguyen
Participant
Participant

Well it's caused by the syntax is different between 2 Python versions, 2.7 and 3.5. So technically what you can do for now is going to Maya script folder , which is normally inside your document folder, go to script and aim for the python file of the tool which you're currently having the issue. You can open it with any note programs like Notepad or Notepad++ (though Notepad++ will require you to install it, Notepad in the other hand is built in with Windows). Hit Ctrl-F and search for the word "print". You'll need to replace all those "print something" lines to "print(something)" (something is in a pair of parenthesis). Ctrl-S to save it and restart Maya.

Well it's caused by the syntax is different between 2 Python versions, 2.7 and 3.5. So technically what you can do for now is going to Maya script folder , which is normally inside your document folder, go to script and aim for the python file of the tool which you're currently having the issue. You can open it with any note programs like Notepad or Notepad++ (though Notepad++ will require you to install it, Notepad in the other hand is built in with Windows). Hit Ctrl-F and search for the word "print". You'll need to replace all those "print something" lines to "print(something)" (something is in a pair of parenthesis). Ctrl-S to save it and restart Maya.

Message 8 of 25

the_michael_davies
Community Visitor
Community Visitor

I seem to be getting a variation of this for a few different modules:

# Error: No module named 'urllib2'
# Traceback (most recent call last):
# File "<maya console>", line 13, in <module>
# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'urllib2' #

 

and when trying to simply run:

import pymel.core as pmc

 

# Error: No module named 'pymel'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'pymel' #

 

Any thoughts?

0 Likes

I seem to be getting a variation of this for a few different modules:

# Error: No module named 'urllib2'
# Traceback (most recent call last):
# File "<maya console>", line 13, in <module>
# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'urllib2' #

 

and when trying to simply run:

import pymel.core as pmc

 

# Error: No module named 'pymel'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'pymel' #

 

Any thoughts?

Message 9 of 25
zewt
in reply to: Hai__Nguyen

zewt
Collaborator
Collaborator

It's not related, you're just seeing "shiboken" because of some nasty code that a QT library is doing.  Turn on History > Show Stack Trace to see where the errors are actually coming from.

 

urllib2 doesn't exist in Python 3 since it's been merged into urllib.  You're probably using a plugin that hasn't been updated yet, but I can't tell which without a full stack trace.  It's probably something you need to ask the developer about.

 

Make sure that you installed PyMEL when you installed Maya 2022.  For some reason there's a checkbox to disable it and it downloads it instead of just installing it like it used to.  (Don't ask me why...)  You can also run this to install it manually instead of reinstalling:

 

"C:\Program Files\Autodesk\Maya2022\bin\mayapy.exe" -m pip install --user pymel

 

It's not related, you're just seeing "shiboken" because of some nasty code that a QT library is doing.  Turn on History > Show Stack Trace to see where the errors are actually coming from.

 

urllib2 doesn't exist in Python 3 since it's been merged into urllib.  You're probably using a plugin that hasn't been updated yet, but I can't tell which without a full stack trace.  It's probably something you need to ask the developer about.

 

Make sure that you installed PyMEL when you installed Maya 2022.  For some reason there's a checkbox to disable it and it downloads it instead of just installing it like it used to.  (Don't ask me why...)  You can also run this to install it manually instead of reinstalling:

 

"C:\Program Files\Autodesk\Maya2022\bin\mayapy.exe" -m pip install --user pymel

 

Message 10 of 25
the_michael_davies
in reply to: zewt

the_michael_davies
Community Visitor
Community Visitor

Weird... it seems it must have been disabled then. Running that line activated it, but then disabled Maya from launching, which required a quick re-install. All good now! Thank you!

0 Likes

Weird... it seems it must have been disabled then. Running that line activated it, but then disabled Maya from launching, which required a quick re-install. All good now! Thank you!

Message 11 of 25
Anonymous
in reply to: Hai__Nguyen

Anonymous
Not applicable

Can someone explain a bit in an easier way what is going on here? I'm taking python classes at the moment, but I'm not quite ready to understand this type of problem. Although I really like reading about more complex problems and understanding the answer, it makes me feel smarter than I actually am at the moment. It's a change of career for me, and I'll be honest, it was influenced by watching my boys take classes of python coding for kids, it made me realize that maybe there could be something for me as well.

0 Likes

Can someone explain a bit in an easier way what is going on here? I'm taking python classes at the moment, but I'm not quite ready to understand this type of problem. Although I really like reading about more complex problems and understanding the answer, it makes me feel smarter than I actually am at the moment. It's a change of career for me, and I'll be honest, it was influenced by watching my boys take classes of python coding for kids, it made me realize that maybe there could be something for me as well.

Message 12 of 25
odiusg
in reply to: Hai__Nguyen

odiusg
Explorer
Explorer

Having the same issue. Shiboken2 is causing some interference in some way. The script editor just has this in its bottom dialog:

import pymel.core as pm

 

And it generates this error
import pymel.core as pm
# Error: No module named 'pymel'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "D:\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'pymel' #

Having the same issue. Shiboken2 is causing some interference in some way. The script editor just has this in its bottom dialog:

import pymel.core as pm

 

And it generates this error
import pymel.core as pm
# Error: No module named 'pymel'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "D:\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
# return original_import(name, *args, **kwargs)
# ModuleNotFoundError: No module named 'pymel' #

Message 13 of 25
zewt
in reply to: odiusg

zewt
Collaborator
Collaborator

That's not related to shiboken (though a shiboken bug is causing it to appear in the error message), it's because you don't have PyMEL installed.

 

Did you uncheck PyMEL in the installer while installing Maya?

 

0 Likes

That's not related to shiboken (though a shiboken bug is causing it to appear in the error message), it's because you don't have PyMEL installed.

 

Did you uncheck PyMEL in the installer while installing Maya?

 

Message 14 of 25
gmdaniel3d
in reply to: zewt

gmdaniel3d
Community Visitor
Community Visitor

Good afternoon, my name is Daniel. I have the same problem that the title of this thread mentions, however in my case the problem is not the print (""),
in my case it does not recognize the module that is in the project. However if I run it in Maya2020 (python2.7) it works without problem. The error it shows me is something with the shiboken2.

Please, if anyone can help me I will be eternally grateful.
* I prepared a video so that you can understand me,
excuse me that I do not speak English.

Thank you very much to all.
 

 

0 Likes

Good afternoon, my name is Daniel. I have the same problem that the title of this thread mentions, however in my case the problem is not the print (""),
in my case it does not recognize the module that is in the project. However if I run it in Maya2020 (python2.7) it works without problem. The error it shows me is something with the shiboken2.

Please, if anyone can help me I will be eternally grateful.
* I prepared a video so that you can understand me,
excuse me that I do not speak English.

Thank you very much to all.
 

 

Message 15 of 25

roklywangQ5XVV
Explorer
Explorer

If anyone still suffering with this issue then try this!
https://matiascodesal.com/blog/how-to-launch-maya-2022-with-python-2-if-you-are-not-ready-for-python... 

maya_shortcut_edit.original.png
Try Option 1!
Hope it works!

If anyone still suffering with this issue then try this!
https://matiascodesal.com/blog/how-to-launch-maya-2022-with-python-2-if-you-are-not-ready-for-python... 

maya_shortcut_edit.original.png
Try Option 1!
Hope it works!

Message 16 of 25
Anonymous
in reply to: roklywangQ5XVV

Anonymous
Not applicable
Thank you. It works
0 Likes

Thank you. It works
Message 17 of 25
TimSiberia
in reply to: roklywangQ5XVV

TimSiberia
Participant
Participant

Awesome. Thank a lot!

0 Likes

Awesome. Thank a lot!

Message 18 of 25
Anonymous
in reply to: roklywangQ5XVV

Anonymous
Not applicable

This works like a charm, Thank You  😊

0 Likes

This works like a charm, Thank You  😊

Message 19 of 25

lucas.langou
Community Visitor
Community Visitor

Hey, 
Your link is dead, does i have just to copy those lines in the shortcut tab ? 
ty 

Hey, 
Your link is dead, does i have just to copy those lines in the shortcut tab ? 
ty 

Message 20 of 25
Hans_Redman
in reply to: gmdaniel3d

Hans_Redman
Advocate
Advocate

.

0 Likes

.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report