简体   繁体   中英

Pyinstaller: No such file or directory: '.xlsx'

I am packaging my code using pyinstaller using the below statement in powershell it completes successfully but when attempting to launch the packaged executable file I get error message.

Error Message:

"FileNotFoundError: [Errno 2] No such file or directory: 'BaseMap.xlsx'"

I am am new to Python and I have read forum after forum and cannot seem to figure why my xlsx file does not seem to be packaged with pyinstaller so that it can be read with the code I wrote. Any guidance or suggestions would be greatly appreciated. Thank you in advance.

pyinstaller statement being used:

pyinstaller --onefile --add-data BaseMap.xlsx;BaseMap.xlsx gmplotguiwithQT2Radius.py

Code:

#!/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_())

Your Command is right. You just need to have both .exe and .xlsx files in one folder. And before that, when commanding pyinstaller you should have that .xlsx file in that folder with .py program file. It worked for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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