[英]PyInstaller - FileNotFoundError: No such file or directory: ''
[英]Pyinstaller: No such file or directory: '.xlsx'
我正在使用 pyinstaller 在 powershell 中使用以下语句打包我的代码,它成功完成,但是在尝试启动打包的可执行文件时,我收到错误消息。
错误信息:
“FileNotFoundError: [Errno 2] 没有这样的文件或目录:'BaseMap.xlsx'”
我是 Python 新手,我在一个又一个论坛上阅读了论坛,似乎无法弄清楚为什么我的 xlsx 文件似乎没有用 pyinstaller 打包,以便可以使用我编写的代码读取它。 任何指导或建议将不胜感激。 先感谢您。
正在使用的 pyinstaller 语句:
pyinstaller --onefile --add-data BaseMap.xlsx;BaseMap.xlsx gmplotguiwithQT2Radius.py
代码:
#!/usr/bin/env python3
# import packages
import sys
import pandas as pd
import gmplot as gm
import PyQt5
import GmapGUI
from PyQt5.QtWidgets import QDialog,QApplication
from PyQt5.QtCore import QUrl
from GmapGUI import *
class MyForm(QDialog):
def __init__ (self):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.ui.search.clicked.connect(self.dispmessage)
self.show()
def dispmessage(self):
# call the program from cmd line
print ("enter file:", sys.argv[0])
# reading data from file
data = pd.read_excel("BaseMap.xlsx")
# create 2 lists latitudes and longitudes
lats = data["fldLat"]
long = data["fldLong"]
#bid = data['fldTgbid']
address = data['fldAddress']
city = data['fldCity']
state = data['fldState']
zipcode = data['fldZip']
# initializing the first location coordinates
gmp = gm.GoogleMapPlotter(lats[0], long[0], 10, apikey = 'API KEY')
#Circle
# Radius unit measure is Meters: 1609.34 Meters = 1 Mile | 8046.72 Meter = 5 Miles | 16093.4 Meters = 10 Miles
for lat, lng in zip(lats, long):
gmp.circle(lat, lng, 5632.7, 'cornflowerblue')
#gmp.circle(lats[0], long[0], 8046.72, 'cornflowerblue')+
#Marker
for lati, lngi, addresses, cities, states, zipc in zip(lats, long, address, city, state, zipcode):
gmp.marker(lati, lngi, '#DB7093', c = None, title = addresses + ' ' + cities + ' ' + states + ' ' + str(zipc))
#Draw
# output the locations
gmp.draw("basemap.html")
file = 'C:/Google Map/GoogleMap_env/basemap.html'
self.ui.webEngineView.setUrl(QUrl(file))
if __name__=="__main__":
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
你的命令是对的。 您只需要在一个文件夹中同时拥有 .exe 和 .xlsx 文件。 在此之前,当命令pyinstaller
您应该在该文件夹中拥有该 .xlsx 文件和 .py 程序文件。 它对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.