Code compatibility

31 views
Skip to first unread message

Brenda Bell

unread,
Oct 19, 2020, 4:47:10 AM10/19/20
to PyInstaller
I have a simple HTTP server written in python. I have it running on an EC2 instance where it's publicly available.

After several of my users expressed an interest in being able to run the app locally, I decided to use pyinstaller to package and distribute.

I was able to make it work, but now I'm faced with a situation where the code as written will either work from a pyinstaller binary or from my EC2 instance, but not both. For instance, I had to change the way I was getting paths for my data files. In pyinstaller, I'm using os.path.join(os.path.dirname(sys.executable), 'logging.conf'), but my EC2 deployment finds files by the path of the loaded module.

The other difference is the destination for my log files (/tmp for the pyinstaller executable and /var/log for EC2).

Would love to hear suggestions and/or best practices for doing this sort of thing. I really don't want to run the pyinstaller executable on my EC2 instance.

Steve Barnes

unread,
Oct 19, 2020, 5:58:14 AM10/19/20
to pyins...@googlegroups.com

Brenda,

 

The most usual methods are:

  1. Having all of the methods that are impacted in one module and
  2. Having pyinstaller have a different variant of that file to the EC2 or
  3. Using if hasattr(sys, “frozen”) to detect if you are running from the installer or EC2 at the moment or
  4. Using sys.platform to see where you are running
  5. Using environment variables on one/both, (possibly with fall-back values), or
  6. Having a config file (different initial config supplied on each platform
  7. Trying the values that definitely won’t work if you are on one platform and then falling back to what will work on the other or both.
  8. See https://pyinstaller.readthedocs.io/en/v3.3.1/runtime-information.html  for some other possibilities.

 

Steve Barnes

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/b873f1b4-0b29-4585-931b-8b5ffc49418cn%40googlegroups.com.

 

bwoodsend

unread,
Oct 19, 2020, 6:24:18 AM10/19/20
to PyInstaller

Does this page in the docs not solve your problem. You should be able to specify if pyinstaller: do x; else: do y. Or the approach that I prefer is to modify the dest parameter in your --add-datas options to put the data files where they’re expected to be by your code (see the updated but not yet published version of that web page which now showcases this).

Brenda Bell

unread,
Oct 19, 2020, 9:02:55 AM10/19/20
to PyInstaller
Awesome.

Brenda Bell

unread,
Oct 19, 2020, 9:02:59 AM10/19/20
to PyInstaller
Thanks for the suggestions and links. That's a big help.

Brenda

Reply all
Reply to author
Forward
0 new messages