0

I have a python script that takes data from an excel file (database.xlsx). I want to freeze the script (ecobel.py) using pyinstaller.

I'd like to know if in the python script I should use the current path where the database file is or if I should reference where I'm putting it in the executable path. I'm currently just calling the path where I'd normally put the database file on my laptop.

In addition, after entering the right path, I'm currently typing this in the comand prompt:

--onefile --add-data database.xlsx;. ecobel.py

which returns "No such file or directory: 'database.xlsx'" when launching the formed executable file.

6
  • This can help: stackoverflow.com/questions/57611000/… Commented Aug 29, 2019 at 7:14
  • Hi, I had seen the post thanks, but even after reading it it's still quite obscure how I should do it. His code isn't commented enough for me Commented Aug 30, 2019 at 15:01
  • Add a minimal version of your code so we can help. Commented Aug 30, 2019 at 15:38
  • Thanks, solved the problem thanks to this page: stackoverflow.com/questions/53587322/… Will update my post with solution Commented Aug 30, 2019 at 16:32
  • It is better to add the answer as Answer, so can help others with a similar problem. Commented Aug 30, 2019 at 16:40

1 Answer 1

1

I Solved it thanks to this page: How do I include files with pyinstaller?

I put the database.xlsx in a file called database at the same directory level as where ecobel.py is.

I call database.xlsx this way in my ecobel.py script:

import sys
if getattr(sys, 'frozen', False):
    database = xlrd.open_workbook(os.path.join(sys._MEIPASS,'database/database.xlsx'))
else:
    database = xlrd.open_workbook('database/database.xlsx')

Then I type this in the command prompt:

--clean -y -n "ecobel" --add-data="database\database.xlsx;database" ecobel.py

"ecobel" will put the .exe file in a folder called ecobel. Don't know what -y and -n stand for, nor what --clean does, if someone can help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.