我正在使用gmplot在谷歌地图上绘制标记。在使用pyinstaller创建exe文件之前,一切都运行得很好。我无法通过gmp.draw将标记绘制到我的map.html中。执行pyinstaller时没有显示错误。当我执行我的exe文件时,错误显示
Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1705, in __call__
  File "test.py", line 792, in plotmap
    gmap.draw('map.html')
  File "site-packages\gmplot\gmplot.py", line 1050, in draw
  File "site-packages\gmplot\gmplot.py", line 1121, in _write_html
  File "site-packages\gmplot\gmplot.py", line 1187, in write_points
  File "site-packages\gmplot\gmplot.py", line 1228, in write_point
  File "site-packages\gmplot\gmplot.py", line 164, in __init__
  File "site-packages\gmplot\utility.py", line 68, in _get_embeddable_image
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI366362\\gmplot\\markers/000000.png'我试着通过添加
gmp.coloricon = "http://www.googlemapsmarkers.com/v1/%s/"但是什么都没有改变。
下面是我关于gmplot的代码
import gmplot
import webbrowser
from tkinter import *
import tkinter as tk
def plotmap():
    # Create the map plotter:
    apikey = '' # (your API key here)
    gmap = gmplot.GoogleMapPlotter(37.766956, -122.448481, 14, apikey=apikey)
    # Outline the Golden Gate Park:
    golden_gate_park = zip(*[
        (37.771269, -122.511015),
        (37.773495, -122.464830),
        (37.774797, -122.454538),
        (37.771988, -122.454018),
        (37.773646, -122.440979),
        (37.772742, -122.440797),
        (37.771096, -122.453889), 
        (37.768669, -122.453518),
        (37.766227, -122.460213),
        (37.764028, -122.510347)
    ])
    gmap.polygon(*golden_gate_park, color='cornflowerblue', edge_width=10)
    # Highlight some attractions:
    attractions_lats, attractions_lngs = zip(*[
        (37.769901, -122.498331),
        (37.768645, -122.475328),
        (37.771478, -122.468677),
        (37.769867, -122.466102),
        (37.767187, -122.467496),
        (37.770104, -122.470436)
    ])
    gmap.scatter(attractions_lats, attractions_lngs, color='#3B0B39', size=40, marker=False)
    # Mark a hidden gem:
    gmap.marker(37.770776, -122.461689, color='cornflowerblue')
    # Draw the map:
    gmap.draw('map.html')
    webbrowser.open('map.html')
root = tk.Tk()
b = tk.Button(root, text= "plot on map", command=plotmap)
b.pack()
root.mainloop()发布于 2020-08-03 15:20:17
最后,我在github上得到了答案,问题是目录中没有这样的数据,相反,gmplot市场将在site-package\gmplot中。因此,这个问题是由于pyinstaller没有链接包造成的。为了解决这个问题,我们需要使用钩子来钩住数据(标记)
1.添加一个目录“hooks”,并将hooks-gmplot.py放入其中。请注意,.py文件需要是hook- the _package_ need _ to _hook.py,否则它将失败
2.在hook-gmplot.py中,放入以下内容
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('gmplot')
#datas = collect_data_files('C:\Python37\Lib\site-packages\gmplot') will raise input error3.在CMD中键入以下pyinstaller命令
pyinstaller -F test.py —additional-hooks-dir=hooks https://stackoverflow.com/questions/63178893
复制相似问题