image source
Repository: Python, Open Source Repository
Software: For software download python 3.0 compatible with your OS here
Difficulty : Basic
What you will learn:
In this tutorial you will learn how to
Using the pyinstaller
How to change our file to .exe system readable format.
Enable our program to run on startup
For my previous posts in the python tutorial series
-Click Here* Creating a simple calculator using python 3.8(cpython)
Creating an encryption key(Cryptography)
- Part 1
- Part 2
- Part 3
- Part 4
Developing an institutions data collection backend and frontend with python 3.6 series
Part 1 of this series
Part 2 of this series
Part 3 of this series
Part 4 of this series
Part 5 of this series
Part 6 of this series
Earlier on this series
Automating OnScreen Processes
Screen Mapping and Navigation
Tutorial
In the last of this series we developed a steemit feed bot that can locate your browser, load your steemit feed and explore this feed for you. Although our code works perfectly we havent yet created a user interface and our code is still in py format which cannot be executed outside our python editor. This tutorial would be covering that.
First things first we need to install a new module within our cmd console.
Modules
Navigate to your python folder and run these lines of code to install pyinstaller;
pip install pyinstaller
Note
pip is already installed in all versions of python from >3.4
Py Installer
Py installer is a packaging file that would help us change our program to a exe which is the normal readable format for windows files. After we install this module, we have to find a suitable icon for our program.
Note: This icon must be in .ico format to be able to be read and should be in the same folder with our python code.
Use shift + right click to open your command prompt module within this folder
#Use this code to compile your file to exe in your command prompt module
pyinstaller -w -F "my steemit feed bot"
To add the icon use while in the same directory
pyinstaller -i "my steemit feed bot"
Deploying
The next thing we have to do is to deploy our application whenever we start up our system.
To do this create a shortcut for our exe executable file then navigate to your local disk and look for this directory which is available by default in windows.
The file path should be
C:/ ProgramData/Microsoft/Windows/StartMenu/Programs
Navigate to this folder and place the shortcut at this location for it to startup whenever the system comes on.
Common Bugs and Fixes
A common bug in systems with smaller RAMs or slower processors is that the desktop may not have fully loaded when your program begins to run and hence because it works with image recognition would not log the coordinates of your browser. To fix this
import pyautogui
import time
time.sleep(120)
def openchrome():
chromeIcon = pyautogui.locateCenterOnScreen('C:/Users/ZEOY/Pictures/Screenshots/python/chromeIcon.png')
print(chromeIcon)
pyautogui.doubleClick(chromeIcon)
time.sleep(3.0)
def maximizetab():
maximizebutton = pyautogui.locateCenterOnScreen('C:/Users/ZEOY/Pictures/Screenshots/python/maximize.png')
print(maximizebutton)
pyautogui.click(maximizebutton)
time.sleep(4)
Simply use the sleep function to make the program give the system time to boot.
Please feel free to share any other bot encountered when trying to run this program on your system
You can find my Code in Github