ID 133803 - import nuke - importing nuke in a python script overwrites sys.argv

Follow

Problem summary

When you import the Nuke module in an external python module, you lose access to the original Python sys arguments.

This makes it tricky to use Nuke in external scripts if you're passing in a several of arguments 

This also means that the following example in the Python dev-guide does not work as expected:
http://docs.thefoundry.co.uk/nuke/80/pythondevguide/nuke_as_python_module.html
 

Customer reported version
Nuke 8.0v1

 

Customer reported platform
windows10

 

Steps to reproduce

1 )  Create a python script with the following contents


# nukeTest.pyimport sysprint "print sys.argv before importing Nuke"print sys.argvimport nukeprint "print sys.argv after importing Nuke"print sys.argv# end

 

2 )  Open a terminal or command prompt and navigate to the Nuke install directory.

 

3 )  Within terminal, change directories to your Python scripts location:


cd /your/Python/Script/nukeTest.py

 

4 ) Launch Nuke Python with your script, add some arguments:


 "C:\Program Files\Nuke11.1v1\python" nukeTest.py test1 test2 100

 

Result )  Your terminal will print the following:

Workaround
You can workaround this problem by preserving sys.argv in another variable before you import Nuke.

Edit the reproduction script with the following:


import sysprint("print sys.argv before importing Nuke")print(sys.argv)sysArgv = sys.argvimport nukeprint("print sys.argv after importing Nuke") print(sys.argv)print "Saved Variable: ",sysArgv

 

Reproduced by support
 

This bug has been reproduced in:

Nuke11.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke11.0v3 - Windows 7 - Mac10.12 - CentOS6.9
Nuke11.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.5v7 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.5v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.0v6 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke9.0v9 - Windows 7 - Mac10.12 - CentOS6.9
Nuke9.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke8.0v7 - Windows 7 - Mac10.12 - CentOS6.9|
Nuke7.0v10 - Windows 7 - Mac10.12 - CentOS6.9

Earliest version tested
- This issue appears to be in all versions of the product

 

Expected behaviour
'sys.argv' should not be overwritten by the Nuke module.  ( e.g  Nuke.exe does not overwrite the function)

 

Actual behaviour
The system 'sys.argv' is overwritten by the Imported Nuke module.

 

    We're sorry to hear that

    Please tell us why