2

I have download and installed Pyinstaller via pip with the goal of making an .exe binary that will be usable stand-alone on windows. My app/script is mostly similar to this one, downloading images from a certain subreddit (which is accessible without a reddit account).

Running the .py script via console or through my IDE works as expected, both on Linux and Windows. According to the PRAW documentation there has to be a C:\Users\myName\AppData\praw.ini config file post-PRAW's installation but it's currently missing from my system, yet, as I mentioned, the script runs just fine when on the python interpreter.

Packaging it into an .exe with Pyinstaller works fine but running it (with or w/o admin rights) fails with the following error

C:\Users\John\IdeaProjects\monsteraday-subreddit-image-downloader\dist>monsteraday-image-downloader.exe
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 363, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python27\lib\site-packages\praw\__init__.py", line 40, in <module>
    from praw.settings import CONFIG
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 363, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python27\lib\site-packages\praw\settings.py", line 47, in <module>
    CONFIG = _load_configuration()
  File "C:\Python27\lib\site-packages\praw\settings.py", line 45, in _load_configuration    .format(locations))
Exception: Could not find config file in any of: [u'C:\\Users\\John\\AppData\\Local\\Temp\\_MEI52442\\praw\\praw.ini', u'C:\\Users\\John\\AppData\Roaming\\praw.ini', u'praw.ini']
monsteraday-image-downloader returned -1

At this point I should clarify that both

  • running python myscript.py in the console
  • executing the pyinstaller generated myscript.exe via console or double-clicking

Were tried on the same Win8.1 x64 machine, with all required libraries (including PRAW) installed, Python 2.7 32-bit (for compatibility of the target .exe) and the user praw.ini config missing from /AppData/ dir, while the global praw.ini properly in C:\Python27\Lib\site-packages\praw\praw.ini

Pyinstaller documentation mentions the usage of the .spec file to include external files in the wrapped .exe but I don't see how this play any role since I already lack/don't need the praw.ini configuration. Py2exe also produces the same results. How can I fix this and produce a straightforward way to use this tool?

6
  • 1
    The documentation doesn't say that an ini is needed in AppData. It says that an ini is needed but the global ini always exists in the package's location. A user ini may appear in AppData to override settings. If the package isn't installed on a machine, there will be no global ini and the script will probably fail. Did you try to run the executable on a machine that doesn't have PRAW installed? Nov 12, 2015 at 15:16
  • The stack trace is pretty clear that PRAW checked only the user and local ini locations before failing. Checking the source code, it seems that the package's location wasn't found in line 31. This could be an issue with how PyInstaller imports packages, judging from other SO questions Nov 12, 2015 at 16:16
  • @PanagiotisKanavos In other words, I probably need to package the global .ini praw config as well via pyinstaller's .spec file? Nov 12, 2015 at 16:20
  • Not necessarilly, found this similar question for Linux. In this case it was permissions issue that hid the file from the user's account. You can use Process Monitor to check for ACCESS DENIED errors when running your application, to check whether this is really the problem Nov 12, 2015 at 16:37
  • Shouldn't the fact that I tried (multiple times) "run as Administrator" on the console which I used to run the .exe cover the permission scenario you describe? Nov 12, 2015 at 16:40

1 Answer 1

0

Based on the last line of the output

Exception: Could not find config file in any of: [u'C:\\Users\\John\\AppData\\Local\\Temp\\_MEI52442\\praw\\praw.ini', u'C:\\Users\\John\\AppData\Roaming\\praw.ini', u'praw.ini']

It seems that PRAW, when run from a packaged .exe, is looking for its config file 'praw.ini' in 3 distinct locations

  1. A temp folder created in the user's system directories, presumably as instructed by pyinstaller
  2. The user's Roaming folder (in Windows)
  3. ., in the same path the .exe is run from

Now, let's see what we can do to qualify for at least one of these cases.

  1. It might be possible to tweak pyinstaller's settings and .spec file in a way that it takes a certain praw.ini file (like the global one found in Pytho's installed packages folder for PRAW) and places it in the temp folder so that the script can use but there doesn't seem to be an easy/direct way to do that. It definitely seems the most "proper" way to do it though.
  2. Having each user place a config file there is bad for UX and should be avoided, unless of course there is an automated installation involved to do it, which might be overkill if we're talking about a small program.
  3. The last is not ideal, but it's a decent compromise and definitely easy to roll with developer-side. All it takes is for the user to have the praw.ini in the same folder he/she is running the .exe from. The executable can be shared within a .zip archive containing a copy of the praw.ini as well, so that when run by the user it will be fully operational without extra effort on their behalf.

Even though it's actually a workaround, the last option will provide enough simplicity for the tool to be working out-of-the-box for an average user.

4
  • Actually, this is wrong and makes some wrong assumptions. Applications are supposed to store their data in the user profile's AppData folder instead of the application's folder, both for security reasons (Program Files is read-only to prevent tampering) and manageability (the roaming profile follows the user in all the machines he logs on, is well known to backup applications and is automatically backed up). A configuration file that doesn't change though, should be stored in the program's folder. So, none of these options is a workaround, but in this case, the correct one would be #3 Nov 13, 2015 at 8:02
  • Also, PRAW doesn't change its behaviour when run from a packaged exe - it always checks all four folders (package, temp, appdata, local). The source proves that Nov 13, 2015 at 8:04
  • In any case, if you want to deploy an exe on a machine that doesn't have the package installed, you'll have to provide the config file somewhere Nov 13, 2015 at 8:05
  • @Panagiotis yeah I reached the same conclusion. I mostly mentioned the first two cases for the sake of completion as they seemed valid options, even if unattainable to my knowledge. The weird thing however is that according to the exception I posted, PRAW only mentions 3 locations. It doesn't seem to check pythons installed packages dir (where I had my only ini) and might be why it won't run even in machines with PRAW installed. Nov 13, 2015 at 10:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.