简体   繁体   English

如何在通过 pyinstaller 创建 exe 文件时包含 timzonefinder 模块

[英]How to include timzonefinder module while creating an exe file via pyinstaller

I'm trying to create an GUI which, on the basis of user's choice gets the lat and long of US states from a CSV file and gets the current time in that state using timezonefinder and datetime module.我正在尝试创建一个 GUI,它根据用户的选择从 CSV 文件中获取美国各州的纬度和经度,并使用timezonefinder和 datetime 模块获取该 state 中的当前时间。

I understand that few states have 2 time zones, but getting only 1 time zone is fine for this project.我知道很少有州有 2 个时区,但只有 1 个时区对这个项目来说很好。 While I'm able to properly use the code and it functions perfectly as a python script, but when I convert it into an executable using pyinstaller , I get a FileNotFound Error .虽然我能够正确使用代码并且它作为 python 脚本完美运行,但是当我使用pyinstaller将它转换为可执行文件时,我得到了FileNotFound Error

Here is the code:这是代码:

import pandas
from tkinter import *
from tkinter import messagebox
from datetime import datetime
from timezonefinder import TimezoneFinder
import pytz

def get_time(state_choosen):
    
    tf =   TimezoneFinder()
    states_data = pandas.read_csv('data/us_states.csv')
    data_list = states_data.to_dict('records')
    
    for data in data_list:
        if state_choosen == data['state']:
            longitude = data['longitude']
            latitude = data['latitude']
            t_zone = tf.timezone_at(lng=longitude, lat=latitude)    
    
            tzone = pytz.timezone(t_zone)
            current_time = datetime.now(tz=tzone).strftime("%I:%M:%S %p")
            
            return current_time 

And here is the error I get:这是我得到的错误:

Traceback (most recent call last):
  File "tkinter\__init__.py", line 1892, in __call__
  File "main.py", line 179, in city_time
    current_time = us_time.get_time(city)
  File "us_time.py", line 10, in get_time
    tf =   TimezoneFinder()
  File "timezonefinder\timezonefinder.py", line 260, in __init__
  File "timezonefinder\timezonefinder.py", line 118, in __init__
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\vaibhav\\AppData\\Local\\Temp\\_MEI71562\\timezonefinder\\poly_zone_ids.bin'

Please suggest how can I fix this error.请建议我如何解决此错误。 or if there is a workaround by including another library that is supported by pyinstaller , or maybe creating an executable by something other then pyinstaller ?或者是否有解决方法,包括 pyinstaller 支持的另一个库,或者可能通过pyinstaller pyinstaller东西创建可执行文件?

I'm but a novice right now, so please suggest the best course of action.我现在只是一个新手,所以请建议最好的行动方案。

Add this parameter to the command line when running pyinstaller:运行pyinstaller时在命令行添加这个参数:

--collect-data timezonefinder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM