我正在使用pyinstaller在powershell中使用以下语句打包代码,该代码已成功完成,但是在尝试启动打包的可执行文件时收到错误消息。
错误消息:
“ FileNotFoundError:[错误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_())
答案 0 :(得分:0)
您的命令正确。您只需要在一个文件夹中同时包含.exe和.xlsx文件。在此之前,在命令pyinstaller
时,应该在该文件夹中包含.py程序文件的.xlsx文件。它对我有用!