2016-06-22 2 views
2

Ich bin gezwungen, Python2.6 für ein CGI-Projekt zu verwenden und versuche mit Plotly Histogramme zu erstellen.Wie soll ich einen Patchy-Syntaxfehler unter Python2.6 patchen?

Hier ist die Funktion, die meine Histogramm Abbildung erzeugt:

def getHistogram(self, dataset_uuid, target, title, xaxisTitle, yaxisTitle): 
    maxThreshold = self.getMaxThreshold(dataset_uuid, target) 

    thresholds = [0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5] 
    counts = [] 

    for i, percentage in enumerate(thresholds): 

     # Query the database for all of the records with frequencies above the 
     # threshold. 
     result = (self.session.query(Mesh) 
      .filter(Mesh.frequency >= percentage * maxThreshold) 
     ) 

     # Appends the fetched record count to the list of counts 
     counts.append(result.count()) 

     # Change percentages from float to integer 
     thresholds[i] = percentage * 100 

    graph = go.Histogram(
     x = thresholds, 
     y = counts, 
     type='bar' 
    ) 

    layout = go.Layout(
     title = title, 
     xaxis = dict(
      title = xaxisTitle 
     ), 
     yaxis = dict(
      title = yaxisTitle 
     ) 
    ) 

    data = [graph] 
    figure = go.Figure(data = data, layout = layout) 

    return json.dumps(figure, cls=plotly.utils.PlotlyJSONEncoder) 

Unter python2.7 mein Skript wie erwartet läuft, aber wenn ich 2.6 versuche ich die folgenden Syntaxfehler angezeigt:

Traceback (most recent call last): 
    File "index.cgi", line 4, in <module> 
    from viads import Application 
    File "/Library/WebServer/Documents/viads/viads/__init__.py", line 3, in <module> 
    from application import Application 
    File "/Library/WebServer/Documents/viads/viads/application.py", line 8, in <module> 
    from mysqlDatabase import MysqlDatabase 
    File "/Library/WebServer/Documents/viads/viads/mysqlDatabase.py", line 3, in <module> 
    from database import Database 
    File "/Library/WebServer/Documents/viads/viads/database.py", line 9, in <module> 
    import plotly.plotly 
    File "/Library/Python/2.6/site-packages/plotly/__init__.py", line 31, in <module> 
    from plotly import (plotly, graph_objs, grid_objs, tools, utils, session, 
    File "/Library/Python/2.6/site-packages/plotly/plotly/__init__.py", line 10, in <module> 
    from . plotly import (
    File "/Library/Python/2.6/site-packages/plotly/plotly/plotly.py", line 114 
    user_plot_options = {k: v for k, v in user_plot_options.items() 
           ^
SyntaxError: invalid syntax 

plotly.py Untersuchung ergab folgende Liste Verständnis:

user_plot_options = {k: v for k, v in user_plot_options.items()    
         if k in default_plot_options} 

Ich glaube, dass versucht wird, die Liste der Doubles in ein Wörterbuch der Plotly-Konfigurationsoptionen zu konvertieren.

Da dies ein Syntaxfehler innerhalb der Plotly-Quelle selbst für Python2.6 ist, sollte ich das für mein eigenes Projekt patchen und erwägen, es zurück zu Plotly zu bringen?

P.S. Ich verstehe die Nachteile der Verwendung älterer Versionen von Python und der Verwendung von FCGI

Antwort

1

Ich löste dies durch die Installation einer älteren Version von Plotly, insbesondere Version 1.6.7 von https://github.com/plotly/plotly.py/releases.

+0

Ich habe die ältere Version installiert, aber es unterstützt keine Offline-Funktion. Finden Sie heraus, wie Sie die neueste Version verwenden? danke –

+0

Nicht mit cPython 2, nein. Wenn Sie Python 2 verwenden möchten, könnte möglicherweise eine neuere Version von Plotly mit der Offline-Funktion rückwärts portiert werden. Ehrlich gesagt, wäre eine bessere Option, Sie alle Ihre Plotten mit der Javascript-Version von Plotly tun, um aus dem Versions-Problem zu entkommen. – drewgun

Verwandte Themen