AWS Thinkbox Discussion Forums

AttributeError: 'module' object has no attribute 'Image'

Hi…

I’ve been fighting this for a while and haven’t figured out why Draft will not load an image. Here’s the code I’m using and a copy of the output… I thought maybe it was an issue with the slashes but swapping them to forward slashes doesn’t change anything.

I’m using 6.2 on Win7. Any ideas would be greatly appreciated:

	[code]
	draftRepoPath = Path.Combine( RepositoryUtils.GetRootDirectory(), "Draft" )
	
	if SystemUtils.IsRunningOnMac():
		draftRepoPath = Path.Combine( draftRepoPath, "Mac" )
	else:
		if SystemUtils.IsRunningOnLinux():
			draftRepoPath = Path.Combine( draftRepoPath, "Linux" )
		else:
			draftRepoPath = Path.Combine( draftRepoPath, "Windows" )
		
		if SystemUtils.Is64Bit():
			draftRepoPath = Path.Combine( draftRepoPath, "64bit" )
		else:
			draftRepoPath = Path.Combine( draftRepoPath, "32bit" )
	
	#import Draft and do the actual conversion
	ClientUtils.LogText( "Appending '%s' to Python search path" % draftRepoPath )
	if not str(draftRepoPath) in sys.path:
		sys.path.append( draftRepoPath )
	ClientUtils.LogText( "SysPath: '%s'" % sys.path )	
	
	ClientUtils.LogText( "Importing Draft to perform Thumbnail conversion..."  )
	try:
		import Draft
		ClientUtils.LogText("Sucessfully imported Draft!")
	except:
		ClientUtils.LogText("Failed to import Draft!")
		ClientUtils.LogText(traceback.format_exc())
		
	try:
		ClientUtils.LogText( "Reading in image '%s'"  % pathToFrame )
		originalImage = Draft.Image.ReadFromFile( pathToFrame )
	except:
		ClientUtils.LogText("Failed to read image")
		ClientUtils.LogText(traceback.format_exc())[/code]

Output:
Sucessfully imported Draft!
Reading in image ‘I:\PRJ\0_TEST\TEST\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v21\TST_001_COMP_NukeTEST_v21.0006.jpg’
Failed to read image
Traceback (most recent call last):
File “none”, line 143, in ConvertThumbnail
AttributeError: ‘module’ object has no attribute ‘Image’

Thanks,
Andrew

I don’t see where you’re setting pathToFrame… is line 32 in this code line 143 in your script? And I’m assuming you are only showing a portion of the output, since there are output lines in this code that don’t appear in your output.

Line #31 (here, 142 yours) appears to print pathToFrame fine, but line #32 (143) it looks like the filename being sent to ReadFromFile is ‘none’. I’ll see if I can replicate this at work tomorrow… what version of draft are you using? (It should print out in the log.)

Thanks!
Andrea

Okay…

So, “none” appears to be the name of the script file. I can get “AttributeError: ‘module’ object has no attribute ‘***’” when I misspell ‘Image’ in ‘Draft.Image.ReadFromFile’, but copying and pasting your line of code doesn’t generate an error. I suspect that you have something called Draft that’s being imported that isn’t actually our Draft library. Could you please run the draft\Samples\Diagnostics\check_Draft_install.py script and let me know the output? (The deadline submitter will require you to specify an input file… pick whatever, the script won’t actually look at it.)

Thanks!
Andrea

Hi Andrea,

Here is the output from the diagnostics script:

=======================================================
Log

0: Task timeout is disabled.
0: Loaded job: TST_001_COMP_NukeTEST_v21.nk [DRAFT] (540f44ea29dc9415e47078ff)
0: INFO: Executing plugin script C:\Users\render\AppData\Local\Thinkbox\Deadline6\slave\R06\plugins\540f44ea29dc9415e47078ff\Draft.py
0: INFO: Found Draft python module at: ‘C:\Users\render\AppData\Local\Thinkbox\Deadline6\slave\R06\Draft\Draft.pyd’
0: INFO: About: Draft Plugin for Deadline
0: INFO: The current environment will be used for rendering
0: Plugin rendering frame(s): 1-10
0: INFO: Draft job starting…
0: INFO: Stdout Handling Enabled: True
0: INFO: Popup Handling Enabled: False
0: INFO: Using Process Tree: True
0: INFO: Hiding DOS Window: True
0: INFO: Creating New Console: False
0: INFO: Looking for bundled python at: ‘C:\Program Files\Thinkbox\Deadline6\bin\dpython.exe’
0: INFO: Executable: “C:\Program Files\Thinkbox\Deadline6\bin\dpython.exe”
0: INFO: Argument: -u “C:\Users\render\AppData\Local\Thinkbox\Deadline6\slave\R06\jobsData\540f44ea29dc9415e47078ff\check_Draft_install.py” nimEncodeSRGB=True username=“Andrew Sinagra” entity=“TST_001_COMP_NukeTEST_v21.nk” version="" width=2048 height=1556 frameList=1-10 startFrame=1 endFrame=10 inFile=“I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v21\TST_001_COMP_NukeTEST_v21.####.jpg” outFile=“I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v21\Draft\TST_001_COMP_NukeTEST_v21.mov” outFolder=“I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v21\Draft” deadlineJobID=540f44e612f5572020c5042c deadlineRepository=“R:\Repository” taskStartFrame=1 taskEndFrame=10
0: INFO: Startup Directory: “C:\Users\render\AppData\Local\Thinkbox\Deadline6\slave\R06\Draft”
0: INFO: Process Priority: BelowNormal
0: INFO: Process Affinity: default
0: INFO: Process is now running
0: STDOUT: ****** Attempting to import Draft. ******
0: STDOUT: Draft 1.1.1.55749
0: STDOUT: *** Draft imported successfully! You’re good to go! ***
0: STDOUT: Draft version 1.1.1.55749
0: STDOUT: Note: If you are getting errors when running a Draft script, look for errors in the script, or with the input to the script.
0: INFO: Process exit code: 0
0: INFO: Draft job complete!

=======================================================
Details

Date: 09/09/2014 11:20:44
Frames: 1-10
Job Submit Date: 09/09/2014 11:20:39
Job User: andrew
Average RAM Usage: 0 (0%)
Peak RAM Usage: 0 (0%)
Average CPU Usage: 0%
Peak CPU Usage: 0%

=======================================================
Slave Information

Slave Name: R06
Version: v6.2.0.32 R (2563d5bc8)
Operating System: Windows 7 Professional (SP1)
Machine User: render
IP Address: fe80::91f4:136:28b0:a7bd%14
MAC Address: 00:30:48:CB:B7:70
CPU Architecture: x64
CPUs: 16
CPU Usage: 0%
Memory Usage: 2.2 GB / 16.0 GB (13%)
Free Disk Space: 151.741 GB
Video Card: Standard VGA Graphics Adapter


This is part of a larger script but here’s the code for the full function. I have a lot of try/excepts because I was trouble shooting…

[code]def ConvertThumbnail( self, pathToFrame, format ):
ClientUtils.LogText( “ConvertThumbnail:” )
#first figure out where the Draft folder is on the repo
draftRepoPath = Path.Combine( RepositoryUtils.GetRootDirectory(), “Draft” )

	if SystemUtils.IsRunningOnMac():
		draftRepoPath = Path.Combine( draftRepoPath, "Mac" )
	else:
		if SystemUtils.IsRunningOnLinux():
			draftRepoPath = Path.Combine( draftRepoPath, "Linux" )
		else:
			draftRepoPath = Path.Combine( draftRepoPath, "Windows" )
		
		if SystemUtils.Is64Bit():
			draftRepoPath = Path.Combine( draftRepoPath, "64bit" )
		else:
			draftRepoPath = Path.Combine( draftRepoPath, "32bit" )
	
	#import Draft and do the actual conversion
	ClientUtils.LogText( "Appending '%s' to Python search path" % draftRepoPath )
	if not str(draftRepoPath) in sys.path:
		sys.path.append( draftRepoPath )
	ClientUtils.LogText( "SysPath: '%s'" % sys.path )	
	
	ClientUtils.LogText( "Importing Draft to perform Thumbnail conversion..."  )
	try:
		import Draft
		ClientUtils.LogText("Sucessfully imported Draft!")
	except:
		ClientUtils.LogText("Failed to import Draft!")
		ClientUtils.LogText(traceback.format_exc())
		
	try:
		ClientUtils.LogText( "Reading in image '%s'"  % pathToFrame )
		originalImage = Draft.Image.ReadFromFile( pathToFrame )
	except:
		ClientUtils.LogText("Failed to read image")
		ClientUtils.LogText(traceback.format_exc())

	try:
		ClientUtils.LogText( "Converting image to type '%s'"  % format )
		tempPath = Path.Combine( ClientUtils.GetDeadlineTempPath(), "%s.%s" % (Path.GetFileNameWithoutExtension(pathToFrame), format) )
		ClientUtils.LogText( "Writing converted image to temp path '%s'..."  % tempPath )
	except:
		ClientUtils.LogText('Failed to convert image.')
		ClientUtils.LogText(traceback.format_exc())
		
	try:
		originalImage.WriteToFile( str(tempPath) )
		ClientUtils.LogText( "Done!" )
	except:
		ClientUtils.LogText('Failed to write file.')
		ClientUtils.LogText(traceback.format_exc())
		
	return tempPath[/code]

The log output looks good… do you also see this line when you run your script?

0: STDOUT: Draft 1.1.1.55749

Why are you adding the draft repository path to your system path? Are you not running through Deadline? Deadline will automatically set up all required environment variables for you… (it’s possible to use Draft outside of Deadline, I’m just wondering which you’re trying to do.)

I was following the lead of the Shotgun.py example that ships with Deadline. If that is incorrect I can remove that line.

This is being called from a custom event script.

Could you zip up the complete script and send it to us? (You can attach it here, or e-mail support.)

(I’ve had a look at Shotgun.py now, and I believe the error is originating elsewhere in the script.)

Sure… here is the full custom event.

Thanks for taking a look.

-Andrew
NIM.rar (6.32 KB)

Hmm, I’m wondering if it’s somehow importing something else as the Draft module… For example, our Draft event plugin is called Draft.py, if this is in the sys.path, it could cause problems.

I noticed your code prints out the sys.path values, what were the paths in there? If [repo path]/events/Draft or [repo path]/plugins/Draft is in there, this is likely the problem. If not, this could still be the problem, but might be happening upstream of your event plugin somehow, since our Python environment is persistent (we don’t compartmentalize event plugins to their own scope in 6.0+).

To help us figure out what’s going on, I’d modify this bit of code:

ClientUtils.LogText( "Importing Draft to perform Thumbnail conversion..." ) try: import Draft ClientUtils.LogText("Sucessfully imported Draft!") except: ClientUtils.LogText("Failed to import Draft!") ClientUtils.LogText(traceback.format_exc())

To this:

[code] ClientUtils.LogText( “Importing Draft to perform Thumbnail conversion…” )
try:
import Draft
ClientUtils.LogText( “Draft members before reload:” )
for key in Draft.dict:
ClientUtils.LogText( key )

     Draft = reload( Draft )

     ClientUtils.LogText( "Draft members after reload:" )
     for key in Draft.__dict__:
        ClientUtils.LogText( key )
     ClientUtils.LogText("Sucessfully imported Draft!")
  except:
     ClientUtils.LogText("Failed to import Draft!")
     ClientUtils.LogText(traceback.format_exc())[/code]

The code I added just prints out the names of all the members present in the Draft module object, forces Python to reload the module (which does NOT happen on its own if it’s already been loaded in memory), and prints out the member names again. If you could post the output that this generates, it should be super helpful!

The reload() statement might even fix the problem; if that’s the case you can just take out the for loops and leave the reload statement in. I’d still like you to post the output if that’s the case though, I’d be real curious to know what was initially loaded as a ‘Draft’ module that caused this problem to begin with.

Cheers,
Jon

Hi Jon…

Thanks… here is the output:

=======================================================
Log

OnJobFinished:
NIM URL: 192.168.1.199/nimAPI.php?
NIM_5.0 - Plugin Type: Nuke
NIM_5.0 - Draft Upload: True
Found NIM Job: ‘I:/PRJ/0_NIM_TEST/NIM/IMG/TST_001/COMP:NIM:TST_001’
NIM jobID: 2476
NIM taskID: 13383
NIM encodeSRGB: True
JobID: 540f659812f5572398e42598
JobName: TST_001_COMP_NukeTEST_v21.nk
JobPlugin: Nuke
JobFrames: 1-10
Output Dirs: I:/PRJ/0_NIM_TEST/NIM/IMG/TST_001/COMP/TST_001_COMP_NukeTEST_v21|
Output Files: TST_001_COMP_NukeTEST_v21.####.jpg|
Start Date: 2014-09-09 00:00:00
End Date: 0001-01-01 00:00:00
No NIM version found. Defaulting to NIM v5.0
Query URL: 192.168.1.199/nimAPI.php?totalTi … ileID=None
Succesfully published to NIM.
ConvertThumbnail:
Appending ‘R:\Repository\Draft\Windows\64bit’ to Python search path
SysPath: ‘[‘C:\Program Files\Thinkbox\Deadline6\bin\lib’, ‘C:\Program Files\Thinkbox\Deadline6\bin\Dlls’, ‘C:\Program Files\Thinkbox\Deadline6\bin\python26.zip’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\plat-win’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\lib-tk’, ‘C:\Program Files\Thinkbox\Deadline6\bin’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\site-packages’, ‘C:\Windows\Microsoft.NET\Framework64\v4.0.30319\’, u’C:\Program Files\Thinkbox\Deadline6\bin\UI’, u’R:\Repository\Draft\Windows\64bit’]’
Importing Draft to perform Thumbnail conversion…
Draft members before reload:
IODescriptionAttribute
StackTrace
PerformanceCounterPermissionAttribute
DeadlineEventListener
DebuggerNonUserCodeAttribute
CounterCreationDataCollection
subprocess
TextWriter
UnescapedXmlDiagnosticData
DraftEventListener
TraceSource
Stopwatch
EventLogPermission
PerformanceCounterPermissionAccess
StreamWriter
DataReceivedEventArgs
WaitForChangedResult
ICollectData
ProcessPriorityClass
FileSystemInfo
RepositoryUtils
FileMode
Path
PerformanceCounterManager
ErrorEventHandler
EventLogPermissionEntryCollection
MemoryStream
SourceSwitch
file
FileSystemEventArgs
DeadlineScriptEngine
TraceFilter
IOException
EventTypeFilter
Debug
DriveType
ThreadState
UnmanagedMemoryAccessor
BufferedStream
PerformanceCounterCategoryType
Debugger
File
DelimitedListTraceListener
SourceLevels
SlaveUtils
FileVersionInfo
EventLogEntry
RenamedEventArgs
CorrelationManager
DeadlineEventManager
DeadlineScriptManager
WatcherChangeTypes
StackFrame
TraceListener
FileOptions
PerformanceCounterType
DiagnosticsConfigurationHandler
PerformanceCounterInstanceLifetime
NotifyFilters
TextReader
ClientUtils
EventLog
XmlWriterTraceListener
DebuggerHiddenAttribute
EventInstance
DebuggerStepThroughAttribute
FrameUtils
DebuggerBrowsableAttribute
StreamReader
FileSystemEventHandler
ThreadPriorityLevel
SearchOption
DriveInfo
InvalidDataException
SourceFilter
BooleanSwitch
CommentUtils
builtins
UnmanagedMemoryStream
SeekOrigin
PerformanceCounterPermissionEntryCollection
EventLogEntryType
Directory
name
DebuggerTypeProxyAttribute
ProcessThread
InternalBufferOverflowException
TextWriterTraceListener
sys
FileLoadException
Stream
DirectoryUtils
MonitorUtils
SwitchLevelAttribute
CounterCreationData
DeadlineEventPluginException
ProcessModule
ProcessModuleCollection
ProcessStartInfo
os
HandleInheritability
FileStream
RenamedEventHandler
InstanceData
DeadlineScriptManagerOutput
JobUtils
DebuggerStepperBoundaryAttribute
ConditionalAttribute
TraceSwitch
PerformanceCounterCategory
SystemUtils
DebuggerVisualizerAttribute
DebuggerDisplayAttribute
TraceLevel
DeadlineEventPlugin
TraceOptions
GetDeadlineEventListener
EventLogPermissionAccess
ScriptUtils
doc
InstanceDataCollection
ExceptionUtils
PulseUtils
FileShare
FileNotFoundException
CounterSampleCalculator
StringWriter
Switch
FileInfo
CloudUtils
InstanceDataCollectionCollection
PathTooLongException
EndOfStreamException
Process
EventSourceCreationData
CleanupDeadlineEventListener
FileSystemWatcher
ThreadWaitReason
DriveNotFoundException
EntryWrittenEventArgs
FileAttributes
EventLogEntryCollection
TraceEventCache
TraceScriptManagerOutput
TimeSpan
StringReader
CounterSample
BinaryWriter
EventLogPermissionAttribute
TraceEventType
EventLogPermissionEntry
ErrorEventArgs
PerformanceCounter
TraceListenerCollection
Trace
PathUtils
DebuggableAttribute
package
ProcessWindowStyle
TraceLogRetentionOption
EventSchemaTraceListener
BinaryReader
EntryWrittenEventHandler
DebuggerBrowsableState
ProcessThreadCollection
DefaultTraceListener
PerformanceCounterPermissionEntry
ProcessUtils
PerformanceCounterPermission
DirectoryInfo
FileUtils
SwitchAttribute
OverflowAction
ScriptType
FrameListUtils
DirectoryNotFoundException
FileAccess
DataReceivedEventHandler
ConsoleTraceListener
EventLogTraceListener
MonitoringDescriptionAttribute
StringUtils
re
Draft members after reload:
IODescriptionAttribute
StackTrace
PerformanceCounterPermissionAttribute
DeadlineEventListener
DebuggerNonUserCodeAttribute
CounterCreationDataCollection
subprocess
TextWriter
UnescapedXmlDiagnosticData
DraftEventListener
TraceSource
Stopwatch
VideoEncoder
EventLogPermission
PerformanceCounterPermissionAccess
StreamWriter
DataReceivedEventArgs
WaitForChangedResult
ICollectData
ProcessPriorityClass
FileSystemInfo
RepositoryUtils
FileMode
Path
PerformanceCounterManager
ErrorEventHandler
EventLogPermissionEntryCollection
MemoryStream
SourceSwitch
file
FileSystemEventArgs
DeadlineScriptEngine
TraceFilter
IOException
EventTypeFilter
Debug
DriveType
ThreadState
UnmanagedMemoryAccessor
BufferedStream
PerformanceCounterCategoryType
Debugger
File
DelimitedListTraceListener
SourceLevels
SlaveUtils
FileVersionInfo
EventLogEntry
RenamedEventArgs
CorrelationManager
DeadlineEventManager
DeadlineScriptManager
WatcherChangeTypes
StackFrame
TraceListener
FileOptions
PerformanceCounterType
DiagnosticsConfigurationHandler
PerformanceCounterInstanceLifetime
NotifyFilters
TextReader
ClientUtils
EventLog
XmlWriterTraceListener
DebuggerHiddenAttribute
EventInstance
DebuggerStepThroughAttribute
FrameUtils
DebuggerBrowsableAttribute
StreamReader
ColorRGBA
FileSystemEventHandler
ThreadPriorityLevel
SearchOption
DriveInfo
InvalidDataException
SourceFilter
BooleanSwitch
CommentUtils
builtins
UnmanagedMemoryStream
SeekOrigin
LibraryInfo
PerformanceCounterPermissionEntryCollection
EventLogEntryType
Directory
name
DebuggerTypeProxyAttribute
Anchor
ProcessThread
InternalBufferOverflowException
TextWriterTraceListener
sys
FileLoadException
Stream
DirectoryUtils
MonitorUtils
SwitchLevelAttribute
CounterCreationData
DeadlineEventPluginException
ProcessModule
ProcessModuleCollection
ProcessStartInfo
LUT
os
HandleInheritability
FileStream
RenamedEventHandler
InstanceData
DeadlineScriptManagerOutput
JobUtils
DebuggerStepperBoundaryAttribute
ConditionalAttribute
FontTypeMetric
TraceSwitch
PerformanceCounterCategory
SystemUtils
DebuggerVisualizerAttribute
DebuggerDisplayAttribute
TraceLevel
DeadlineEventPlugin
TraceOptions
GetDeadlineEventListener
EventLogPermissionAccess
ScriptUtils
doc
InstanceDataCollection
ExceptionUtils
PulseUtils
FileShare
FileNotFoundException
CounterSampleCalculator
StringWriter
PositionalGravity
Switch
FileInfo
CloudUtils
InstanceDataCollectionCollection
PathTooLongException
ImageInfo
EndOfStreamException
Process
AnnotationInfo
EventSourceCreationData
CleanupDeadlineEventListener
FileSystemWatcher
ThreadWaitReason
CompositeOperator
DriveNotFoundException
EntryWrittenEventArgs
Image
FileAttributes
EventLogEntryCollection
TraceEventCache
TraceScriptManagerOutput
TimeSpan
StringReader
CounterSample
QTFastStart
BinaryWriter
EventLogPermissionAttribute
TraceEventType
EventLogPermissionEntry
ErrorEventArgs
PerformanceCounter
TraceListenerCollection
Trace
PathUtils
DebuggableAttribute
package
ProcessWindowStyle
TraceLogRetentionOption
EventSchemaTraceListener
BinaryReader
EntryWrittenEventHandler
DebuggerBrowsableState
ProcessThreadCollection
DefaultTraceListener
VideoDecoder
PerformanceCounterPermissionEntry
ProcessUtils
PerformanceCounterPermission
DirectoryInfo
FileUtils
SwitchAttribute
OverflowAction
ScriptType
FrameListUtils
DirectoryNotFoundException
FileAccess
DataReceivedEventHandler
ConsoleTraceListener
EventLogTraceListener
MonitoringDescriptionAttribute
StringUtils
re
Sucessfully imported Draft!
Reading in image ‘I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v21\TST_001_COMP_NukeTEST_v21.0006.jpg’
Failed to read image
Traceback (most recent call last):
File “none”, line 162, in ConvertThumbnail
ArgumentError: Python argument types in
Image.ReadFromFile(unicode)
did not match C++ signature:
ReadFromFile(class std::basic_string<char,struct std::char_traits,class std::allocator > filename, class py_image_info {lvalue} imageInfo=<Draft.ImageInfo object at 0x000000001FF02DB0>)
Failed to Apply LUT
Traceback (most recent call last):
File “none”, line 171, in ConvertThumbnail
UnboundLocalError: local variable ‘originalImage’ referenced before assignment
Converting image to type ‘jpg’
Writing converted image to temp path ‘C:\Users\render\AppData\Local\Thinkbox\Deadline6\temp\TST_001_COMP_NukeTEST_v21.0006.jpg’…
Failed to write file.
Traceback (most recent call last):
File “none”, line 186, in ConvertThumbnail
UnboundLocalError: local variable ‘originalImage’ referenced before assignment
WARNING: Could not find converted thumbnail.
Skipping Thumnail Upload to NIM.

=======================================================
Details

Date: 09/09/2014 13:40:12
Event Type: OnJobFinished
Frames: (no task)
Job User: andrew
Job Submit Date: 09/09/2014 13:39:53

=======================================================
Slave Information

Slave Name: Z31
Version: v6.2.0.32 R (2563d5bc8)
Operating System: Windows 7 Professional (SP1)
Machine User: render
IP Address: fe80::7d8e:efdd:9bcb:ce9b%29
MAC Address: 00:25:90:5A:A5:7A
CPU Architecture: x64
CPUs: 32
CPU Usage: 3%
Memory Usage: 4.7 GB / 64.0 GB (7%)
Free Disk Space: 299.664 GB
Video Card: Standard VGA Graphics Adapter

Yup, it’s definitely finding the wrong Draft. Let’s try adding the Draft path at the beginning, instead of the end of PATH… change line 129 from:

sys.path.append( draftRepoPath ) to:

sys.path.insert(1,draftRepoPath)

If that doesn’t solve the issue, try doing a ClientUtils.LogText( Draft.file ) after doing the Draft import. This should tell you which file Python actually loaded the module from, and help us find the culprit.

Hey all,

Looks like the sys.path.insert did the trick and I need to include the Draft = reload( Draft ), but here’s the really odd thing.

When I add ClientUtils.LogText( Draft.file ) to the code that fails using sys.path.append I get this:

Appending ‘R:\Repository\Draft\Windows\64bit’ to Python search path
SysPath: ‘[‘C:\Program Files\Thinkbox\Deadline6\bin\lib’, u’R:\Repository\Draft\Windows\64bit’, ‘C:\Program Files\Thinkbox\Deadline6\bin\Dlls’, ‘C:\Program Files\Thinkbox\Deadline6\bin\python26.zip’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\plat-win’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\lib-tk’, ‘C:\Program Files\Thinkbox\Deadline6\bin’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\site-packages’, ‘C:\Windows\Microsoft.NET\Framework64\v4.0.30319\’, u’C:\Program Files\Thinkbox\Deadline6\bin\UI’]’
Importing Draft to perform Thumbnail conversion…
Sucessfully imported Draft!
none

However when I use sys.path.insert I get this:

Appending ‘R:\Repository\Draft\Windows\64bit’ to Python search path
SysPath: ‘[‘C:\Program Files\Thinkbox\Deadline6\bin\lib’, u’R:\Repository\Draft\Windows\64bit’, ‘C:\Program Files\Thinkbox\Deadline6\bin\Dlls’, ‘C:\Program Files\Thinkbox\Deadline6\bin\python26.zip’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\plat-win’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\lib-tk’, ‘C:\Program Files\Thinkbox\Deadline6\bin’, ‘C:\Program Files\Thinkbox\Deadline6\bin\lib\site-packages’, ‘C:\Windows\Microsoft.NET\Framework64\v4.0.30319\’, u’C:\Program Files\Thinkbox\Deadline6\bin\UI’]’
Importing Draft to perform Thumbnail conversion…
Sucessfully imported Draft!
R:\Repository\Draft\Windows\64bit\Draft.pyd

I have no clue why it would say it’s been loaded when it says none is the file.

Here’s the working code:

def ConvertThumbnail( self, pathToFrame, format ):
		ClientUtils.LogText( "ConvertThumbnail:" )
		#first figure out where the Draft folder is on the repo
		draftRepoPath = Path.Combine( RepositoryUtils.GetRootDirectory(), "Draft" )
		
		if SystemUtils.IsRunningOnMac():
			draftRepoPath = Path.Combine( draftRepoPath, "Mac" )
		else:
			if SystemUtils.IsRunningOnLinux():
				draftRepoPath = Path.Combine( draftRepoPath, "Linux" )
			else:
				draftRepoPath = Path.Combine( draftRepoPath, "Windows" )
			
			if SystemUtils.Is64Bit():
				draftRepoPath = Path.Combine( draftRepoPath, "64bit" )
			else:
				draftRepoPath = Path.Combine( draftRepoPath, "32bit" )
		
		#import Draft and do the actual conversion
		ClientUtils.LogText( "Appending '%s' to Python search path" % draftRepoPath )
		if not str(draftRepoPath) in sys.path:
			sys.path.insert( 1,draftRepoPath )
		ClientUtils.LogText( "SysPath: '%s'" % sys.path )	
		
		
		ClientUtils.LogText( "Importing Draft to perform Thumbnail conversion..."  )
		try:
			import Draft
			Draft = reload( Draft )
			ClientUtils.LogText("Sucessfully imported Draft!")
			ClientUtils.LogText(Draft.__file__)
		except:
			ClientUtils.LogText("Failed to import Draft!")
			ClientUtils.LogText(traceback.format_exc())
                        
		try:
			ClientUtils.LogText( "Reading in image '%s'"  % pathToFrame )
			originalImage = Draft.Image.ReadFromFile( str(pathToFrame) )
		except:
			ClientUtils.LogText("Failed to read image")
			ClientUtils.LogText(traceback.format_exc())

		# APPLY SRGB LUT
		try:
			if self.nim_encodeSRGB == "True":
				displayLut = Draft.LUT.CreateSRGB()
				displayLut.Apply( originalImage )
				ClientUtils.LogText( 'Encoding sRGB...' )
		except:
			ClientUtils.LogText('Failed to Apply LUT')
			ClientUtils.LogText(traceback.format_exc())
			
		try:
			ClientUtils.LogText( "Converting image to type '%s'"  % format )
			tempPath = Path.Combine( ClientUtils.GetDeadlineTempPath(), "%s.%s" % (Path.GetFileNameWithoutExtension(pathToFrame), format) )
			ClientUtils.LogText( "Writing converted image to temp path '%s'..."  % tempPath )
		except:
			ClientUtils.LogText('Failed to convert image.')
			ClientUtils.LogText(traceback.format_exc())
			
		try:
			originalImage.WriteToFile( str(tempPath) )
			ClientUtils.LogText( "Done!" )
		except:
			ClientUtils.LogText('Failed to write file.')
			ClientUtils.LogText(traceback.format_exc())
			
		return tempPath

Ok… I realized it wasn’t the append vs the insert that was fixing this, but rather:

Draft = reload( Draft ) seems to fix the problem in either case.

Weird… to try to track down the source of this bizarreness, what do you get if you add the following lines (before and/or after the insert to the path):

import imp ( file, path, descr) = imp.find_module( "Draft" ) ClientUtils.LogText( 'Draft found in: %s' % path )

Also… requiring the reload seems to imply that something called Draft was already there… we might get more information if, before importing Draft, you add:

ClientUtils.LogText( 'locals: %s' % locals())

I added this before and after the reload:

try:
	import imp
	(file, path, descr) = imp.find_module( "Draft" )
	ClientUtils.LogText( 'BEFORE: Draft found in:', path )
except:
	ClientUtils.LogText( 'BEFORE: Failed to find Draft' )
	ClientUtils.LogText(traceback.format_exc())

In both cases it returns this which is really odd because it is working, unless I just typed something wrong:

BEFORE: Failed to find Draft
Traceback (most recent call last):
File “none”, line 131, in ConvertThumbnail
TypeError: No method matches given arguments
Inserting ‘R:\Repository\Draft\Windows\64bit’ to Python search path
Importing Draft to perform Thumbnail conversion…
AFTER: Failed to find Draft
Traceback (most recent call last):
File “none”, line 164, in ConvertThumbnail
TypeError: No method matches given arguments
Sucessfully imported Draft!
R:\Repository\Draft\Windows\64bit\Draft.pyd

I think that’s an error about the log line, which I corrected with an edit… I also added another suggestion to that post. Could you have a look at my edited post? (And sorry for making the mistake initially!)

It seems that I am getting inconsistent results… Now sometimes it finds Draft before import… sometimes it doesn’t… the sys.path.insert output here shows that Draft was not found, but in subsequent runnings of the same script it returned identical output to the sys.path.append. At this point I don’t think the append vs the insert matters, but if I don’t reload it, it fails for sure.

Here’s the output. I put the find_module in 3 places…
before import
after import and before reload
after reload…

This output is using the sys.path.append:

ConvertThumbnail:
BEFORE: Draft found in: R:\Repository\Draft\Windows\64bit\Draft.pyd
Appending ‘R:\Repository\Draft\Windows\64bit’ to Python search path
locals: {‘descr’: (’.pyd’, ‘rb’, 3), ‘format’: u’jpg’, ‘pathToFrame’: u’I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v22\TST_001_COMP_NukeTEST_v22.0006.jpg’, ‘imp’: <module ‘imp’ (built-in)>, ‘file’: <open file ‘R:\Repository\Draft\Windows\64bit\Draft.pyd’, mode ‘rb’ at 0x000000001FD96C00>, ‘draftRepoPath’: u’R:\Repository\Draft\Windows\64bit’, ‘path’: ‘R:\Repository\Draft\Windows\64bit\Draft.pyd’, ‘self’: <NIM.NimEventListener object at 0x000000002066D240>}
Importing Draft to perform Thumbnail conversion…
AFTER IMPORT - BEFORE RELOAD: Draft found in: R:\Repository\Draft\Windows\64bit\Draft.pyd
AFTER RELOAD: Draft found in: R:\Repository\Draft\Windows\64bit\Draft.pyd
Sucessfully imported Draft!
R:\Repository\Draft\Windows\64bit\Draft.pyd

This output is using the sys.path.insert:

ConvertThumbnail:
BEFORE: Failed to find Draft
Traceback (most recent call last):
File “none”, line 130, in ConvertThumbnail
ImportError: No module named Draft
Inserting ‘R:\Repository\Draft\Windows\64bit’ to Python search path
locals: {‘imp’: <module ‘imp’ (built-in)>, ‘pathToFrame’: u’I:\PRJ\0_NIM_TEST\NIM\IMG\TST_001\COMP\TST_001_COMP_NukeTEST_v22\TST_001_COMP_NukeTEST_v22.0006.jpg’, ‘format’: u’jpg’, ‘self’: <NIM.NimEventListener object at 0x000000001FE56FC0>, ‘draftRepoPath’: u’R:\Repository\Draft\Windows\64bit’}
Importing Draft to perform Thumbnail conversion…
AFTER IMPORT - BEFORE RELOAD: Draft found in: R:\Repository\Draft\Windows\64bit\Draft.pyd
AFTER RELOAD: Draft found in: R:\Repository\Draft\Windows\64bit\Draft.pyd
Sucessfully imported Draft!
R:\Repository\Draft\Windows\64bit\Draft.pyd

Is there any way a node would retain sys.path info between tasks? It’s the only thing I can think of right now that would explain the inconsistencies.

Yeah, I think insert vs append isn’t going to do much, as, if the reload is required, it thinks draft is already imported. Have you tried using ClientUtils.LogText( ‘locals: %s’ % locals())? Hmmm… locals() appears to return a dictionary… one sec…

Privacy | Site terms | Cookie preferences