执行 pyinstaller 后找不到 gmplot 标记



我正在使用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-packagesgmplotgmplot.py", line 1050, in draw
File "site-packagesgmplotgmplot.py", line 1121, in _write_html
File "site-packagesgmplotgmplot.py", line 1187, in write_points
File "site-packagesgmplotgmplot.py", line 1228, in write_point
File "site-packagesgmplotgmplot.py", line 164, in __init__
File "site-packagesgmplotutility.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()

最后,我在github上得到了答案,问题是该目录中没有这样的数据,相反,gmplot市场将在site package\gmplot内部。因此,问题是由于pyinstaller没有链接包。为了解决这个问题,我们需要使用钩子来钩住数据(标记(

1.添加一个目录"hooks",并将hooks-gmplot.py放在里面。请注意,.py文件需要挂接到e_package_need_to_book.py,否则它将无法通过

2.在hook-job.py中,将以下内容放入

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('gmplot')
#datas = collect_data_files('C:Python37Libsite-packagesgmplot') will raise input error

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

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

相关内容

  • 没有找到相关文章

最新更新