0

I'm trying to convert my python code "new.py" to an exe using pyinstaller. The exe got built successfully but when I try to run it it shows me the following error:

$ /Users/name/Desktop/Programming\ Projects/PythonWebscraper/dist/new ; exit;
Traceback (most recent call last):
  File "new.py", line 37, in <module>
  File "openpyxl/reader/excel.py", line 151, in load_workbook
  File "openpyxl/reader/excel.py", line 115, in _validate_archive
  File "zipfile.py", line 1240, in __init__
FileNotFoundError: [Errno 2] No such file or directory: './PulledData.xlsx'
[78053] Failed to execute script new
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

My code is writing to an excel spread sheet and so it's loading up the file './PulledData.xlsx'. I put the excel sheet in the same directory as the exe that I'm tryin to run, yet it still can't find the excel sheet as shown by the logs. (new.exe and PulledData.xlsx are both in the same directory)

How do I fix this? Is this something to do with Pyinstaller? I don't want to bundle up the excel sheet as it should be easy to access. The exe (python code) should manipulate the excel sheet called "PulledData" in whatever directory its in, how can I do that?

Plzhelp
  • 175
  • 3
  • 13
  • Does this answer your question? [Determining application path in a Python EXE generated by pyInstaller](https://stackoverflow.com/questions/404744/determining-application-path-in-a-python-exe-generated-by-pyinstaller) (Note that the second answer is more up-to-date than the accepted one.) – CrazyChucky Dec 27 '20 at 22:17
  • Oh so the problem is that it's not getting the correct path? So relative paths don't work? Like shouldn't "./PulledData" look at the current directory of the exe? @CrazyChucky – Plzhelp Dec 27 '20 at 22:21
  • Relative paths are relative to the current working directly. That generally works the way you'd expect in a standalone Python script *(and in submodules, if any, in your executable)*, but the way PyInstaller compiles/bundles things alters the process in the *main* Python file. Check the [docs](https://pyinstaller.readthedocs.io/en/stable/runtime-information.html) for more info. – CrazyChucky Dec 27 '20 at 22:24

0 Answers0