1

I'm trying to create an exe file to distribute among users in my company. the exe file open a simple GUI (made with Tkinter), which allows the user to select a txt file from their pc and inserts the data from the txt into a Google sheet. I tested my python script before attempting to turn it into an exe and it worked great. but now, when I'm trying to use Pyinstaller it shows the following error:

Traceback (most recent call last):
    File "pygsheets\sheet.py", line 39, in __init__
    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\<Awais Bin Riaz>\\AppData\\Local\\Temp\\_MEI104322\\pygsheets\\data\\sheets_discovery.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cli.py", line 4, in <module>
    main()
  File "rps_nba\__main__.py", line 272, in main
    client = pygsheets.authorize(service_file = key_file)
  File "pygsheets\authorization.py", line 131, in authorize
  File "pygsheets\client.py", line 61, in __init__
  File "pygsheets\sheet.py", line 42, in __init__
  File "googleapiclient\_helpers.py", line 134, in positional_wrapper
  File "googleapiclient\discovery.py", line 291, in build
  File "googleapiclient\discovery.py", line 405, in _retrieve_discovery_doc
googleapiclient.errors.UnknownApiNameOrVersion: name: sheets  version: v4
[28348] Failed to execute script cli

I find some solution like:

I made a breakthrough with some testing. When I used pyinstaller without the --onefile option, I found the library for pygsheets was missing in the dist folder. I copied my pygsheets folder from the AppData\Local\Programs\Python\Python38\Lib\site-packages folder.

but I don't understand which file or folder I have to copy and where I have to paste it, and also find it

pyinstaller --add-data src-file dst-file

but don't know what is src-file and dst-file, I tried many time but error occured of this

usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--add-data <SRC;DEST or SRC:DEST>]
               [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR] [--hidden-import MODULENAME]
               [--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS] [--exclude-module     EXCLUDES]
               [--key KEY] [-d {all,imports,bootloader,noarchive}] [-s] [--noupx] [--upx-exclude FILE] [-c] [-w]
               [-i <FILE.ico or FILE.exe,ID or FILE.icns or "NONE">] [--version-file FILE] [-m <FILE or XML>]
               [-r RESOURCE] [--uac-admin] [--uac-uiaccess] [--win-private-assemblies] [--win-no-prefer-redirects]
               [--osx-bundle-identifier BUNDLE_IDENTIFIER] [--runtime-tmpdir PATH] [--bootloader-ignore-signals]
               [--distpath DIR] [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
               scriptname [scriptname ...]
pyinstaller: error: argument --add-data: invalid add_data_or_binary value: "'C:\\Users\\AWAIS BIN RIAZ\\AppData\\Local\\Programs\\Python\\Python39\\Lib\\site-packages\\pygsheets\\sheet.py';"

and this error also occured

usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--add-data <SRC;DEST or SRC:DEST>]
               [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR] [--hidden-import MODULENAME]
               [--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
               [--key KEY] [-d {all,imports,bootloader,noarchive}] [-s] [--noupx] [--upx-exclude FILE] [-c] [-w]
               [-i <FILE.ico or FILE.exe,ID or FILE.icns or "NONE">] [--version-file FILE] [-m <FILE or XML>]
               [-r RESOURCE] [--uac-admin] [--uac-uiaccess] [--win-private-assemblies] [--win-no-prefer-redirects]
               [--osx-bundle-identifier BUNDLE_IDENTIFIER] [--runtime-tmpdir PATH] [--bootloader-ignore-signals]
               [--distpath DIR] [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
               scriptname [scriptname ...]
pyinstaller: error: the following arguments are required: scriptname

please guide me to solve this issue, any of the two method is acceptable. Thankyou in advance

  • What is the command you used to make the exe? – Muhd Mairaj May 24 '21 at 17:10
  • In case you have not yet seen [this](https://github.com/nithinmurali/pygsheets/issues/200), the latest reply [in this follow-up thread](https://github.com/nithinmurali/pygsheets/issues/341) is maybe another useful option – lucidbrot May 24 '21 at 17:14
  • I don't know enough to write an answer, but it sounds to me like the pygsheets library is making use of those json files and you'd have to add them to the executable. So they'd probably be the src file for your pyinstaller command. See [here](https://stackoverflow.com/questions/41870727/pyinstaller-adding-data-files) – lucidbrot May 24 '21 at 17:16
  • @MuhdMairaj I use pyinstaller --onefile app.py command to make exe file – Awais Bin Riaz May 24 '21 at 17:24
  • @lucidbrot I already see here but don't understand the command used there – Awais Bin Riaz May 24 '21 at 17:26
  • @AwaisBinRiaz add `--debug` in your command, it should give some useful information – Muhd Mairaj May 24 '21 at 17:26
  • @MuhdMairaj how and where I add --debug – Awais Bin Riaz May 24 '21 at 17:40
  • 1
    @AwaisBinRiaz `pyinstaller --onefile --debug app.py`. Use this command for making the executable – Muhd Mairaj May 24 '21 at 17:41
  • @AwaisBinRiaz Well, I have never used pyinstaller before, but the second answer there explains it and the first answer tells you the command, so I think it is in your case: `pyinstaller -F --add-data "sheets_discovery.json;drive_discovery.json" cli.py`. With the two json files copied from the place where you've tried to get them from. That's probably easier than dealing with the full path because escaping backslashes may or may not be required – lucidbrot May 24 '21 at 17:41
  • @lucidbrot tried but error is occurred – Awais Bin Riaz May 24 '21 at 17:45
  • @AwaisBinRiaz Have you seen [this github issue where 41 people had the same problem](https://github.com/pyinstaller/pyinstaller/issues/3968#issuecomment-564707533)? Combined with the info from [this comment](https://stackoverflow.com/questions/41870727/pyinstaller-adding-data-files/44014560#comment103803422_44014560) I think you will have to use `sheets_discovery.json;.` on windows and `sheets_discovery.json:.` on linux. (I'm replying in comments for now, and if it helps you can write an answer or tell me and I will :) ) – lucidbrot May 25 '21 at 07:29

0 Answers0