【问题标题】:can't find gmplot marker after doing pyinstaller执行 pyinstaller 后找不到 gmplot 标记
【发布时间】:2023-03-16 16:16:01
【问题描述】:

我正在使用 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()

【问题讨论】:

    标签: python google-maps-markers pyinstaller markers gmplot


    【解决方案1】:

    最后,我在 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 error
    

    3. 在 CMD 中输入以下 pyinstaller 命令

    pyinstaller -F test.py —additional-hooks-dir=hooks 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 2020-06-13
      • 2018-01-15
      • 2017-02-02
      • 2013-07-13
      相关资源
      最近更新 更多