https://github.com/slyautomation/osrs_stat_generator
This project incorporates pyinstaller to package the a stat generator project into a executable file. this is a good example of a project that is dependant on images and creating files which can be difficult to work as intended in a exe file.
https://github.com/slyautomation/osrs_stat_generator
Last synced: 2 months ago
JSON representation
This project incorporates pyinstaller to package the a stat generator project into a executable file. this is a good example of a project that is dependant on images and creating files which can be difficult to work as intended in a exe file.
- Host: GitHub
- URL: https://github.com/slyautomation/osrs_stat_generator
- Owner: slyautomation
- Created: 2022-09-20T01:36:40.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-27T23:51:05.000Z (over 1 year ago)
- Last Synced: 2025-01-23T01:09:45.140Z (4 months ago)
- Language: Python
- Homepage: https://www.slyautomation.com/blog/runescape-stat-generator/
- Size: 1.59 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# osrs_stat_generator
Creates a stat card of your desired stats inputted into the userform:
https://www.slyautomation.com/blog/runescape-stat-generator/
Starts with a blank card:

Add in numbers for each skill and press 'Generate Stats':

The result is saved to a png file 'Result.png' located in the same location as the exe file.

This project incorporates pyinstaller to package the project into a executable file. this is a good example of a project that is dependant on images and creating files which can be difficult to work as intended in a exe file.
The main part of the code that helps ensure images and created files are referenced when running the exe file is the resourcepath function.
```
def resourcePath(relativePath):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
basePath = sys._MEIPASS
except Exception:
basePath = os.path.abspath(".")return os.path.join(basePath, relativePath)
```This will save relevent files in you user profile temp folder on your operating system and allows the exe file to run in any location.
Run in the terminal:
```
pyinstaller --noconsole --onefile main.spec
```
--noconsole is a command to ensure the command terminal is hidden and only the app is displayed.--onefile packages the python project into a single exe file
main.spec is a specification config file which details how the pyinstaller will setup the project as an executable file.
```
a = Analysis(['main.py'],
pathex=['C:\\Users\\i7 8700\\PycharmProjects\\osrs_xp_stat_generator'],
binaries=[],
datas=[('C:\\Users\\i7 8700\\PycharmProjects\\osrs_xp_stat_generator\\*.png','.'),('C:\\Users\\i7 8700\\PycharmProjects\\osrs_xp_stat_generator\\images\\','.')],
```An important component to ensure images are built into the exe file is updating the spec file with the path location of the image files and any other files that are needed.
From the above referenced in 'datas=' i want any png file to be included in the packaging in the exe.
Make sure to change the file path as it is set to my userpath. ``` 'C:\\Users\\i7 8700\\PycharmProjects\\osrs_xp_stat_generator\\ ```