简体   繁体   中英

Maya Python: IOError: [Errno 9] Bad file descriptor

I created a maya python toolchain for my team. All works well, just on one machine i seem to have problems. I narrowed it down to the print command. Like this test library called "temp.py":

import os
# from pymel.core import *

print "Hello"

after importing it with

import temp

it produces this output (only on that one computer!):

// Error: 9
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\maya_scripts\temp.py", line 4, in <module>
# print "Hello"
# IOError: [Errno 9] Bad file descriptor //

I've tried Maya Version 2016, 2016.5 and 2017 . All the same result. Python 2.5 as standalone hasn't got that problem. To me that sounds like some kind of configuration problem, but then again it behaves the same over 3 different maya installations, so deleting the prefs didn't help either.

It's hard to know what's really happening here. But try this

import sys
sys.__stdout__.write("hello")
 sys.__stdout__.write(str(sys.stdout))

Then check your output window ( not the listener). In a vanilla maya you'd expect to see something like

<maya.Output object at 0x00000217E827FC10>

after "hello". If you see something else, some script has tried to hijack sys.stdout in this installation. You can probably work around it by creating an environment variable called MAYA_SKIP_USERSETUP_PY , setting it to 1 , and restarting -- that should stop whatever script is being naughty from autoloading.

This ought to reset it to what you're looking for:

 import maya.utils as utils
 sys.stdout = utils.Output()

However you need to comb through the scripts on that machine and find out who is messing with sys.stdout behind your back

The error is from your module, you may overwrite the print function

maya 2016 is python 2.7.6 and maya 2017 is in python 3.x on 2017 you must use print("")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM