首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >执行pyinstaller后找不到gmplot标记

执行pyinstaller后找不到gmplot标记
EN

Stack Overflow用户
提问于 2020-07-31 02:07:46
回答 1查看 173关注 0票数 0

我正在使用gmplot在谷歌地图上绘制标记。在使用pyinstaller创建exe文件之前,一切都运行得很好。我无法通过gmp.draw将标记绘制到我的map.html中。执行pyinstaller时没有显示错误。当我执行我的exe文件时,错误显示

代码语言:javascript
运行
复制
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'

我试着通过添加

代码语言:javascript
运行
复制
gmp.coloricon = "http://www.googlemapsmarkers.com/v1/%s/"

但是什么都没有改变。

下面是我关于gmplot的代码

代码语言:javascript
运行
复制
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()
EN

回答 1

Stack Overflow用户

发布于 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中,放入以下内容

代码语言:javascript
运行
复制
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命令

代码语言:javascript
运行
复制
pyinstaller -F test.py —additional-hooks-dir=hooks 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63178893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档