Search code examples
pythonmayamelnuke

How can I launch Nuke from within Maya?


I seem to be doing something improper here and I am dumbfounded on what it is. I am trying to launch The Foundry NUKE from within Maya, and when I try I get this error relating to a module not found. But if I load up Nuke on a regular command line it loads up perfect fine. Seems something related to Maya's Python interpreter not able to find this module? I can't seem to find it...

Update #1: I have even tried doing some sys.path.appends of the Nuke plugin, DLLs, lib, and include dirs before all of this to no avail...

Update #2: I've reinstalled my Python and verified that it is 64 bit. Also checked my Maya and Nuke versions which are 64 bit. I've tried the following as well... opening up a normal Python command prompt outside of Maya to load Nuke via an os.system call and it works. It is only when doing an os.system call of Nuke in Maya that it fails with problems importing this _socket module. When checking what _socket module Maya is loading I get:

import _socket
print _socket.__file__
C:\Program Files\Autodesk\Maya2016\Python\DLLs\_socket.pyd

Leading me to believe that Maya's Python is loading a diff version of this _socket then what Nuke is and something is going wrong there.

Original Code/Errors:

C:\Program Files\Nuke9.0v8\Nuke9.0.exe
Traceback (most recent call last):
    File "C:/Program Files/Nuke9.0v8/plugins/init.py", line 22, in <module>
      import nukescripts.ViewerProcess
    File "C:/Program Files/Nuke9.0v8/plugins\nukescripts\__init__.py", line 22, in <module>
      from nukeprofiler import *
    File "C:/Program Files/Nuke9.0v8/plugins\nukescripts\nukeprofiler.py", line 2, in <module>
        import socket
    File "C:\Python27\lib\socket.py", line 47, in <module>
        import _socket
ImportError: DLL load failed: The specified module could not be found.
C:/Program Files/Nuke9.0v8/plugins/init.py : error interpreting this plugin

from PySide import QtCore, QtGui
import maya.cmds as cmds
import os, sys
#import subprocess


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(314, 216)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
        Dialog.setSizePolicy(sizePolicy)
        self.blastBtn = QtGui.QPushButton(Dialog)
        self.blastBtn.setGeometry(QtCore.QRect(110, 130, 75, 23))
        self.blastBtn.setObjectName("blastBtn")

        self.blastBtn.clicked.connect(self.RunPlayblast)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Playblast & Nuke Me", None, QtGui.QApplication.UnicodeUTF8))
        self.blastBtn.setText(QtGui.QApplication.translate("Dialog", "Blast", None, QtGui.QApplication.UnicodeUTF8))


    def RunPlayblast(self):
        cmds.playblast(fmt="qt", f="myMovie.mov", fo=True)
        self.RunNuke()

    def RunNuke(self):
        nukeExe = r'C:\Program Files\Nuke9.0v8\Nuke9.0.exe'
        myTemplate = r'B:\home\nukePBTemplate.nk'

        os.system('"'+nukeExe+'" -x ' +myTemplate)

        #command = nukeExe+" -x "+myTemplate
        #subprocess.Popen(command)

if __name__ == '__main__':
    app = QtGui.QApplication.instance() 
    Dialog = QtGui.QDialog()
    blastMe = Ui_Dialog()
    blastMe.setupUi(Dialog)
    Dialog.show()
    app.exec_()

Solution

  • I think you can use built in subprocess to call nuke like this

    import subprocess
    nukeProcess = subprocess.Popen(["C:/Program Files/Nuke9.0v8/Nuke9.0.exe", "-x", "B:/home/nukePBTemplate.nk"])
    

    And I think you never use a mel.eval("system /whatever") since you trying from python, already python has many built in methods to deal with system commands, like subprocess, commands etc ..

    Update

    import subprocess, os
    newEnv = os.environ.copy()
    newEnv["PYTHONPATH"] = newEnv["PATH"] + "/local/share/python/2.7/libs"
    nukeProcess = subprocess.Popen(["C:/Program Files/Nuke9.0v8/Nke9.0.exe", "-x", "B:/home/nukePBTemplate.nk"], env=newEnv)