2017-02-08 3 views
3

Dieser Befehl funktioniert auf meinem PC gut, aber er gibt mir diesen Fehler auf meinem Arbeits-PC. Was könnte passieren? Ich kann das Char_Limits.py-Skript direkt in Powershell ohne ein Problem ausführen. Fehler: Kompilieren 'C: \ Programdata \ Anaconda2 \ lib \ site-packages \ jinja2 \ asyncsupport.py' ist fehlgeschlagen Syntaxerror: invalid syntax (asyncsupport.py, Zeile 22)Python setup.py py2exe Ungültige Syntax (asyncsupport.py, Zeile 22)

Meine setup.py-Datei sieht aus wie :

from distutils.core import setup 
import py2exe 

setup (console=['Char_Limits.py']) 

Meine Datei sieht so aus:

import xlwings as xw 
from win32com.client import constants as c 
import win32api 

""" 
Important Notes: Header row has to be the first row. No columns without a header row. If you need/want a blank column, just place a random placeholder 
header value in the first row. 
Product_Article_Number column is used to determine the number of rows. It must be populated for every row. 
""" 

#functions, hooray! 
def setRange(columnDict, columnHeader): 
    column = columnDict[columnHeader] 
    rngForFormatting = xw.Range((2,column), (bttm, column)) 
    cellReference = xw.Range((2,column)).get_address(False, False) 
    return rngForFormatting, cellReference 

def msg_box(message): 
    win32api.MessageBox(wb.app.hwnd, message) 

#Character limits for fields in Hybris 
CharLimits_Fields = {"alerts":500, "certifications":255, "productTitle":300, 
     "teaserText":450 , "includes":1000, "compliance":255, "disclaimers":9000, 
     "ecommDescription100":100, "ecommDescription240":240, 
     "internalKeyword":1000, "metaKeywords":1000, "metaDescription":1000, 
     "productFeatures":7500, "productLongDescription":1500,"requires":500, 
     "servicePlan":255, "skuDifferentiatorText":255, "storage":255, 
     "techDetailsAndRefs":12000, "warranty":1000} 

# Fields for which a break tag is problematic. 
BreakTagNotAllowed = ["ecommDescription100", "ecommDescription240", "productTitle", 
         "skuDifferentiatorText"]  

app = xw.apps.active       
wb = xw.Book(r'C:\Users\XXXX\Documents\Import File.xlsx') 

#identifies the blanket range of interest 
firstCell = xw.Range('A1') 
lstcolumn = firstCell.end("right").column 

headers_Row = xw.Range((1,1), (1, lstcolumn)).value 
columnDict = {} 

for column in range(1, len(headers_Row) + 1): 
    header = headers_Row[column - 1] 
    columnDict[header] = column 


try: 
    articleColumn = columnDict["Product_Article_Number"] 

except: 
    articleColumn = columnDict["Family_Article_Number"] 

firstCell = xw.Range((1,articleColumn)) 

bttm = firstCell.end("down").row 

wholeRange = xw.Range((1,1),(bttm, lstcolumn)) 
wholeRangeVal = wholeRange.value 

#Sets the font and deletes previous conditional formatting 
wholeRange.api.Font.Name = "Arial Unicode MS" 
wholeRange.api.FormatConditions.Delete() 

for columnHeader in columnDict.keys(): 
    if columnHeader in CharLimits_Fields.keys(): 
     rng, cellRef = setRange(columnDict, columnHeader) 
     rng.api.FormatConditions.Add(2,3, "=len(" + cellRef + ") >=" + str(CharLimits_Fields[columnHeader])) 
     rng.api.FormatConditions(1).Interior.ColorIndex = 3 

    if columnHeader in BreakTagNotAllowed: 
     rng, cellRef = setRange(columnDict, columnHeader) 
     rng.api.FormatConditions.Add(2,3, '=OR(ISNUMBER(SEARCH("<br>",' + cellRef + ')), ISNUMBER(SEARCH("<br/>",' + cellRef + ")))") 
     rng.api.FormatConditions(2).Interior.ColorIndex = 6 

searchResults = wholeRange.api.Find("~\"") 
if searchResults is not None: 
    msg_box("There's a double quote in this spreadsheet") 
else: 
    msg_box("There are no double quotes in this spreadsheet") 

# app.api.FindFormat.Clear 
# app.api.FindFormat.Interior.ColorIndex = 3 
# foundRed = wholeRange.api.Find("*", SearchFormat=True) 

# if foundRed is None: 
    # msg_box("There are no values exceeding character limits") 
# else: 
    # msg_box("There are values exceeding character limits") 

# app.api.FindFormat.Clear 
# app.api.FindFormat.Interior.ColorIndex = 6 
# foundYellow = wholeRange.api.Find("*", SearchFormat=True) 
# if foundYellow is None: 
    # msg_box("There are no break tags in this spreadsheet") 
# else: 
    # msg_box("There are break tags in this spreadsheet") 

Antwort

6

Das Problem:

bei der Suche, was in Zeile 22 auf the github package wahrscheinlich ist:

async def concat_async(async_gen): 

Dies wird die Verwendung des Asynchron-Schlüsselwort zu machen, die in Python 3.5, jedoch hinzugefügt wurden Py2exe unterstützt nur bis zu 3.4 Python. Nun scheint Jinja die Python-Sprache in irgendeiner Weise zu erweitern (vielleicht während der Laufzeit?), Um dieses asynchrone Schlüsselwort in früheren Versionen von Python zu unterstützen. py2exe kann diese Spracherweiterung nicht berücksichtigen.

Die Fix:

Asynchron-Unterstützung wurde in jinja2 Version 2.9 nach the documentation hinzugefügt. Also habe ich versucht, eine frühere Version von Jinja (Version 2.8) zu installieren, die ich downloaded here.

Ich habe eine Sicherung meiner aktuellen Jinja-Installation erstellt, indem ich den Inhalt von %PYTHONHOME%\Lib\site-packages\jinja2 an einen anderen Ort verschoben habe. extrahieren Sie die zuvor tar.gz-Datei heruntergeladen und das Paket über pip installieren:

cd .\Downloads\dist\Jinja2-2.8 # or wherever you extracted jinja2.8 
python setup.py install 

Als Randbemerkung, ich hatte auch meine Rekursion Grenze zu erhöhen, da py2exe die Standardgrenze wurde erreicht.

from distutils.core import setup 
import py2exe 
import sys 
sys.setrecursionlimit(5000) 
setup (console=['test.py']) 

Warnung:

Wenn was auch immer es ist, den Sie verwenden auf der neuesten Version von jinja2 setzt, dann könnte dies fehlschlagen oder haben Auswirkungen unbeabsichtigte Neben, wenn tatsächlich der Code ausgeführt wird. Ich habe ein sehr einfaches Skript zusammengestellt.

+0

gibt es eine Möglichkeit, dies für Python 2.7 zu umgehen? – battery514

+0

Finden Sie heraus, was Sie verwenden, das von asyncsupport.py abhängig ist, und entfernen Sie diese Abhängigkeit. Sie könnten ein Tool wie dieses verwenden, um Ihnen zu helfen: http://stackoverflow.com/a/30450999/3154314 –

+0

Alternativ (wenn Ihr Skript einfach genug ist, um in Python 3-Syntax zu konvertieren) können Sie Python 3.5 verwenden und 'PyInstaller' um es in eine ausführbare Datei wie hier vorgeschlagen zu konvertieren: http://StackOverflow.com/a/33174611/3154314 –