The following is a story that is relevant only to certain Maya versions of Windows. I've never encountered it on a Mac or a recent version of Maya.
If you encounter the mysterious phenomenon that the print command itself causes an error as described above, make sure that MAYA_NO_CONSOLE_WINDOW is not set in the system environment variable.
This is an environment variable that you set to hide the console window. https://support.borndigital.co.jp/hc/ja/articles/360002474194-Maya-%E3%81%AE-Output-Window-%E3%82%92%E9%9D%9E%E8%A1%A8%E7%A4%BA%E3%81%AB%E3%81%99%E3%82%8B
If MAYA_NO_CONSOLE_WINDOW is set, the print statement will not pass in some environments such as Maya 2017 Update 5 (although the exact target version is unknown). As far as I tried, it didn't work even if the set value was 0 instead of 1.
The situation where print does not pass seems to be when the stdout setting is incorrect, and by not displaying the console window, the allocation will be lost.
For the time being, you can fix it by executing the code below, but it seems better to remove the MAYA_NO_CONSOLE_WINDOW definition because something else may be wrong.
# https://stackoverflow.com/questions/43633433/maya-python-ioerror-errno-9-bad-file-descriptor
import maya.utils as utils
sys.stdout = utils.Output()
It's unpleasant that problems occur only in a specific environment.