|
Okay - in my now 4th
annual attempt to move from SPSS v14 to now version 18.0.1
I run a large number
of Ctables from within a begin program - end program python
block
these run perfectly
well - so seemingly the python install is not the issue
I used to have sax
basic code to run a bunch of post table formatting for me and I
updated
this to python code
at v17 that invokes the spss client to do this now and I have that also
running as
expected (seemingly at least) in v17.0.3
I open V17 run the
job and it runs without issue to completion
BUT when I open
V18.0.1 to run the exact same thing it runs my tables - no issues -
but
when it gets to my
formatting routine - it crashes ... it reports:
StartPython has
stopped functioning and has to close - the error in the log is
#6887 Command name:
BEGIN PROGRAM
>External program
failed during initialization.
>Execution of
this command stops.
Any
ideas???????????????
Bunch of ctables
here.
THS IS THE
CALL
sys.path.insert(0,
r"C:\Work\Other\SPSS\Scripts")
import
TWH0906OutputOptions
TWH0906OutputOptions.OutputRoutine()
AND THIS IS TWH0906OutputOptions.py : (apologies if the formatting goes screwy) #**** START MODULE ***** # 1-MODIFIED DECEMBER 2007 TO REDUCE MANY FILES TO 1 # 2-MODIFIED MAY 2009 Version 17 # 3-MODIFIED JUNE 2009 FOR PYTHON """This function will serve as my primary
output formatting function
.It removes all output but pivot tables (CTables) and adds page breaks .It set the print options .It handles table numbering and table of contents creation .It saves output versions along the way and the ultimately in various formats """ __author__ = "TWH" __version__ = "1.0.3" def OutputRoutine(myor = '2', \ mytm = '18', \ mylm = '9', \ myrm = '9', \ mybm = '18', \ mypn = '1', \ UseTableNumbering = False, \ UseTableOfContents = False, \ UseHTMLMarks = False, \ CleanUp = True, \ OutputSPV = True, \ OutputPDF = False, \ OutputHTM = False, \ OutputXLS = False, \ OutputPPT = False): import spss #; help (spss) # Should change this to read directory of open syntax document MyCurrentPath = r'''c:\\Work\\Other\\SPSS\\ExampleSPSS\\''' #; print MyCurrentPath # Should change this to
read name from open syntax document
flename = r'''flename''' #; print flename # CALL & START SPSS CLIENT import
SpssClient
SpssClient.StartClient() # GET DESIGNATED OUTPUT DOC # If multiple output
docs exist - get the list of output docs first and use a
reference
# MyOutputDocLists = SpssClient.GetOutputDocuments() # FirstOutputDoc = MyOutputDocLists.GetItemAt(0) # SELECTS ALL FOR
DELETION EXCEPT RELEVANT PIVOT TABLES
try:
MyOutputDocLists = SpssClient.GetOutputDocuments() MyOutputDoc = SpssClient.GetDesignatedOutputDoc()
MyOutputDoc.SaveAs(MyCurrentPath + flename + "_ORG_" + ".spv")
MyOutputDoc.ClearSelection()
MyOutputDoc.SelectAllCharts() MyOutputDoc.Delete() MyOutputDoc.SelectAllLogs() MyOutputDoc.Delete() MyOutputDoc.SelectAllNotes() MyOutputDoc.Delete() MyOutputDoc.SelectAllText() MyOutputDoc.Delete() MyOutputDoc.SelectAllTitles() MyOutputDoc.Delete() MyOutputDoc.SelectAllWarnings() MyOutputDoc.Delete() except: raise # HERE FOR MERGING IF NECESSARY - MUST RUN BEFORE FORMATTING # OR IF V18 DOES MERGING - MAYBE I WILL JUST NEED TO FORMAT # SELECTS UNNECESSARY PIVOT TABLES (THE TESTS) FOR DELETION AND ADDS PAGE BREAK TO REMAINING PIVOTS
try:
MyOutputDocLists = SpssClient.GetOutputDocuments() MyOutputDoc = SpssClient.GetDesignatedOutputDoc() MyOutputItems = MyOutputDoc.GetOutputItems() PTable = 0 for index in range(MyOutputItems.Size()): MyOutputItem = MyOutputItems.GetItemAt(index) MyItemType = MyOutputItem.GetType() #; print MyItemType MySpecificType = MyOutputItem.GetSpecificType() #; print MySpecificType if MyOutputItem.GetType() == SpssClient.OutputItemType.PIVOT: MyPivotTable = MyOutputItem.GetSpecificType() #; print MyPivotTable sTitle = MyPivotTable.GetTitleText() #;print sTitle if (('Pearson Chi-Square Test' in sTitle) or ('Comparisons of Column' in sTitle)): MyOutputItem.SetSelected(True) else: if PTable > 0: MyOutputItem.SetPageBreak(True) PTable += 1 MyOutputDoc.Delete() MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M1_" + ".spv") except: raise ## PRINT(PAGE) SETUP try: #myor = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.Orientation) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.Orientation,myor) #mytm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.TopMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.TopMargin,mytm) #mylm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.LeftMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.LeftMargin,mylm) #myrm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.RightMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.RightMargin,myrm) #mybm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.BottomMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.BottomMargin,mybm) #mypn = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.StartingPageNumber) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.StartingPageNumber,mypn) #MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.SpaceBetweenItems,) #MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.PrintedChartSize,)
MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M2_" +
".spv")
except: raise #'TABLE NUMBERING AND TABLE OF CONTENTS SETUP #'PROBE FOR TABLE NUMBERING AND TABLE OF CONTENTS. #OPEN BOOKMARKS/TOC/HTML MARKUP FILES - RUN ON CLEANED OUPUT
try:
PTable = 0
FileBookM1 = open(MyCurrentPath + r'''Bookmarks1.txt''',
'w')
FileTOC2 = open(MyCurrentPath + r'''TOC.txt''', 'w') FileHTMLMarks = open(MyCurrentPath + r'''HTMLMarks.txt''', 'w')
MyOutputDoc =
SpssClient.GetDesignatedOutputDoc()
MyOutputItems = MyOutputDoc.GetOutputItems() for index in range(MyOutputItems.Size()): MyOutputItem = MyOutputItems.GetItemAt(index) if MyOutputItem.GetType() == SpssClient.OutputItemType.PIVOT: MyPivotTable = MyOutputItem.GetSpecificType() MyPivotTable.SetUpdateScreen(True) MyPivotTable.ClearSelection() PTable += 1 CurrentTitle = MyPivotTable.GetTitleText()
if
UseTableNumbering:
NewTitle = "Table: " + str(PTable) + CurrentTitle #print NewTitle if UseHTMLMarks: NewTitle = r"""<a name=""" + NewTitle + r"""></a>""" NewTitleHTMLRef = r"""<a href=#""" + NewTitle + r""">""" + "Table: " + str(PTable) + "</a>" MyPivotTable.SelectTitle() MyPivotTable.SetTitleText(NewTitle) MyPivotTable.ClearSelection() if PTable == 1: print "YES-TableNumbers" FileBookM1.write(">" + NewTitle + "\n") else: NewTitle = CurrentTitle if UseHTMLMarks: NewTitle = r"""<a name=""" + NewTitle + r"""></a>""" NewTitleHTMLRef = r"""<a href=#""" + NewTitle + r""">""" + "Table: " + str(PTable) + "</a>" if PTable == 1: print "No-TableNumbers"
if
UseTableOfContents:
NewTitleTOC = CurrentTitle if UseTableNumbering: if UseHTMLMarks: NewTitleTOC = NewTitleHTMLRef else: NewTitleTOC = NewTitle #print NewTitleTOC FileTOC2.write(NewTitleTOC + "\n") if PTable == 1: print "YES-TOC" else: if PTable == 1: print "No-TOC"
if
UseHTMLMarks:
FileHTMLMarks.write(NewTitle + "\n") FileHTMLMarks.write(NewTitleHTMLRef + "\n") if PTable == 1: print "YES-HTML" else: if PTable == 1: print "No-HTML"
FileBookM1.close()
FileTOC2.close() FileHTMLMarks.close()
if UseTableNumbering or UseTableOfContents or
UseHTMLMarks:
MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M3_" + ".spv")
except:
raise # CLOSE ANY&ALL
SYNTAX DOCUMENTS
try: if CleanUp: MySyntaxDocsList = SpssClient.GetSyntaxDocuments() for index in range(MySyntaxDocsList.Size()): MySyntaxDocs = MySyntaxDocsList.GetItemAt(index) MySyntaxDocs.CloseDocument() except: raise # SAVE DESIGNATED OUTPUT DOCUMENT try: MyOutputDoc.SetPromptToSave(True) if OutputSPV: MyOutputDoc.SaveAs(MyCurrentPath + flename + "_FNL_" + ".spv") except: raise # EXPORT AS PDF try: if OutputPDF: fileName = MyCurrentPath + flename + ".pdf" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatPdf) except: raise # EXPORT AS EXCEL try: if OutputXLS: fileName = MyCurrentPath + flename + ".xls" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatXls) except: raise # EXPORT AS POWERPOINT try: if OutputPPT: fileName = MyCurrentPath + flename + ".ppt" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatPpt) except: raise # EXPORT AS HTML try: if OutputHTM: fileName = MyCurrentPath + flename + ".html" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatHtml) except: raise # END SPSS
CLIENT
SpssClient.StopClient() #**** END MODULE ***** Thanks! Tim **************************** Notice: This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient, please
notify the sender immediately by return e-mail, do not use the information,
delete this e-mail and destroy any copies. Any dissemination or use of
this information by a person other than the intended recipient is unauthorized
and may be illegal. Email transmissions cannot be guaranteed to be secure
or error free. The sender therefore does not accept any liability for errors or
omissions in the contents of this message that arise as a result of email
transmissions. |
|
I'm guessing that you have not installed the programmability materials for V18.0.1. Be sure to get the Python essentials from the Developer Central Plug-ins page to match your 18.0.1 version. This can coexist with V17 if desired. Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Okay - in my now 4th annual attempt to move from SPSS v14 to now version 18.0.1 I run a large number of Ctables from within a begin program - end program python block these run perfectly well - so seemingly the python install is not the issue I used to have sax basic code to run a bunch of post table formatting for me and I updated this to python code at v17 that invokes the spss client to do this now and I have that also running as expected (seemingly at least) in v17.0.3 I open V17 run the job and it runs without issue to completion BUT when I open V18.0.1 to run the exact same thing it runs my tables - no issues - but when it gets to my formatting routine - it crashes ... it reports: StartPython has stopped functioning and has to close - the error in the log is #6887 Command name: BEGIN PROGRAM >External program failed during initialization. >Execution of this command stops. Any ideas??????????????? Bunch of ctables here. THS IS THE CALL sys.path.insert(0, r"C:\Work\Other\SPSS\Scripts") import TWH0906OutputOptions TWH0906OutputOptions.OutputRoutine() AND THIS IS TWH0906OutputOptions.py : (apologies if the formatting goes screwy) #**** START MODULE ***** # 1-MODIFIED DECEMBER 2007 TO REDUCE MANY FILES TO 1 # 2-MODIFIED MAY 2009 Version 17 # 3-MODIFIED JUNE 2009 FOR PYTHON """This function will serve as my primary output formatting function .It removes all output but pivot tables (CTables) and adds page breaks .It set the print options .It handles table numbering and table of contents creation .It saves output versions along the way and the ultimately in various formats """ __author__ = "TWH" __version__ = "1.0.3" def OutputRoutine(myor = '2', \ mytm = '18', \ mylm = '9', \ myrm = '9', \ mybm = '18', \ mypn = '1', \ UseTableNumbering = False, \ UseTableOfContents = False, \ UseHTMLMarks = False, \ CleanUp = True, \ OutputSPV = True, \ OutputPDF = False, \ OutputHTM = False, \ OutputXLS = False, \ OutputPPT = False): import spss #; help (spss) # Should change this to read directory of open syntax document MyCurrentPath = r'''c:\\Work\\Other\\SPSS\\ExampleSPSS\\''' #; print MyCurrentPath # Should change this to read name from open syntax document flename = r'''flename''' #; print flename # CALL & START SPSS CLIENT import SpssClient SpssClient.StartClient() # GET DESIGNATED OUTPUT DOC # If multiple output docs exist - get the list of output docs first and use a reference # MyOutputDocLists = SpssClient.GetOutputDocuments() # FirstOutputDoc = MyOutputDocLists.GetItemAt(0) # SELECTS ALL FOR DELETION EXCEPT RELEVANT PIVOT TABLES try: MyOutputDocLists = SpssClient.GetOutputDocuments() MyOutputDoc = SpssClient.GetDesignatedOutputDoc() MyOutputDoc.SaveAs(MyCurrentPath + flename + "_ORG_" + ".spv") MyOutputDoc.ClearSelection() MyOutputDoc.SelectAllCharts() MyOutputDoc.Delete() MyOutputDoc.SelectAllLogs() MyOutputDoc.Delete() MyOutputDoc.SelectAllNotes() MyOutputDoc.Delete() MyOutputDoc.SelectAllText() MyOutputDoc.Delete() MyOutputDoc.SelectAllTitles() MyOutputDoc.Delete() MyOutputDoc.SelectAllWarnings() MyOutputDoc.Delete() except: raise # HERE FOR MERGING IF NECESSARY - MUST RUN BEFORE FORMATTING # OR IF V18 DOES MERGING - MAYBE I WILL JUST NEED TO FORMAT # SELECTS UNNECESSARY PIVOT TABLES (THE TESTS) FOR DELETION AND ADDS PAGE BREAK TO REMAINING PIVOTS try: MyOutputDocLists = SpssClient.GetOutputDocuments() MyOutputDoc = SpssClient.GetDesignatedOutputDoc() MyOutputItems = MyOutputDoc.GetOutputItems() PTable = 0 for index in range(MyOutputItems.Size()): MyOutputItem = MyOutputItems.GetItemAt(index) MyItemType = MyOutputItem.GetType() #; print MyItemType MySpecificType = MyOutputItem.GetSpecificType() #; print MySpecificType if MyOutputItem.GetType() == SpssClient.OutputItemType.PIVOT: MyPivotTable = MyOutputItem.GetSpecificType() #; print MyPivotTable sTitle = MyPivotTable.GetTitleText() #;print sTitle if (('Pearson Chi-Square Test' in sTitle) or ('Comparisons of Column' in sTitle)): MyOutputItem.SetSelected(True) else: if PTable > 0: MyOutputItem.SetPageBreak(True) PTable += 1 MyOutputDoc.Delete() MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M1_" + ".spv") except: raise ## PRINT(PAGE) SETUP try: #myor = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.Orientation) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.Orientation,myor) #mytm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.TopMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.TopMargin,mytm) #mylm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.LeftMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.LeftMargin,mylm) #myrm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.RightMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.RightMargin,myrm) #mybm = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.BottomMargin) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.BottomMargin,mybm) #mypn = MyOutputDoc.GetPrintOptions(SpssClient.PrintOptions.StartingPageNumber) MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.StartingPageNumber,mypn) #MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.SpaceBetweenItems,) #MyOutputDoc.SetPrintOptions(SpssClient.PrintOptions.PrintedChartSize,) MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M2_" + ".spv") except: raise #'TABLE NUMBERING AND TABLE OF CONTENTS SETUP #'PROBE FOR TABLE NUMBERING AND TABLE OF CONTENTS. #OPEN BOOKMARKS/TOC/HTML MARKUP FILES - RUN ON CLEANED OUPUT try: PTable = 0 FileBookM1 = open(MyCurrentPath + r'''Bookmarks1.txt''', 'w') FileTOC2 = open(MyCurrentPath + r'''TOC.txt''', 'w') FileHTMLMarks = open(MyCurrentPath + r'''HTMLMarks.txt''', 'w') MyOutputDoc = SpssClient.GetDesignatedOutputDoc() MyOutputItems = MyOutputDoc.GetOutputItems() for index in range(MyOutputItems.Size()): MyOutputItem = MyOutputItems.GetItemAt(index) if MyOutputItem.GetType() == SpssClient.OutputItemType.PIVOT: MyPivotTable = MyOutputItem.GetSpecificType() MyPivotTable.SetUpdateScreen(True) MyPivotTable.ClearSelection() PTable += 1 CurrentTitle = MyPivotTable.GetTitleText() if UseTableNumbering: NewTitle = "Table: " + str(PTable) + CurrentTitle #print NewTitle if UseHTMLMarks: NewTitle = r"""<a name=""" + NewTitle + r"""></a>""" NewTitleHTMLRef = r"""<a href=#""" + NewTitle + r""">""" + "Table: " + str(PTable) + "</a>" MyPivotTable.SelectTitle() MyPivotTable.SetTitleText(NewTitle) MyPivotTable.ClearSelection() if PTable == 1: print "YES-TableNumbers" FileBookM1.write(">" + NewTitle + "\n") else: NewTitle = CurrentTitle if UseHTMLMarks: NewTitle = r"""<a name=""" + NewTitle + r"""></a>""" NewTitleHTMLRef = r"""<a href=#""" + NewTitle + r""">""" + "Table: " + str(PTable) + "</a>" if PTable == 1: print "No-TableNumbers" if UseTableOfContents: NewTitleTOC = CurrentTitle if UseTableNumbering: if UseHTMLMarks: NewTitleTOC = NewTitleHTMLRef else: NewTitleTOC = NewTitle #print NewTitleTOC FileTOC2.write(NewTitleTOC + "\n") if PTable == 1: print "YES-TOC" else: if PTable == 1: print "No-TOC" if UseHTMLMarks: FileHTMLMarks.write(NewTitle + "\n") FileHTMLMarks.write(NewTitleHTMLRef + "\n") if PTable == 1: print "YES-HTML" else: if PTable == 1: print "No-HTML" FileBookM1.close() FileTOC2.close() FileHTMLMarks.close() if UseTableNumbering or UseTableOfContents or UseHTMLMarks: MyOutputDoc.SaveAs(MyCurrentPath + flename + "_M3_" + ".spv") except: raise # CLOSE ANY&ALL SYNTAX DOCUMENTS try: if CleanUp: MySyntaxDocsList = SpssClient.GetSyntaxDocuments() for index in range(MySyntaxDocsList.Size()): MySyntaxDocs = MySyntaxDocsList.GetItemAt(index) MySyntaxDocs.CloseDocument() except: raise # SAVE DESIGNATED OUTPUT DOCUMENT try: MyOutputDoc.SetPromptToSave(True) if OutputSPV: MyOutputDoc.SaveAs(MyCurrentPath + flename + "_FNL_" + ".spv") except: raise # EXPORT AS PDF try: if OutputPDF: fileName = MyCurrentPath + flename + ".pdf" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatPdf) except: raise # EXPORT AS EXCEL try: if OutputXLS: fileName = MyCurrentPath + flename + ".xls" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatXls) except: raise # EXPORT AS POWERPOINT try: if OutputPPT: fileName = MyCurrentPath + flename + ".ppt" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatPpt) except: raise # EXPORT AS HTML try: if OutputHTM: fileName = MyCurrentPath + flename + ".html" MyOutputDoc.ExportDocument(SpssClient.SpssExportSubset.SpssVisible,fileName,SpssClient.DocExportFormat.SpssFormatHtml) except: raise # END SPSS CLIENT SpssClient.StopClient() #**** END MODULE ***** Thanks! Tim **************************** Notice: This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, do not use the information, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. Email transmissions cannot be guaranteed to be secure or error free. The sender therefore does not accept any liability for errors or omissions in the contents of this message that arise as a result of email transmissions.
|
| Free forum by Nabble | Edit this page |
