[Tutorial] Packaging and deploying(Part 3)

in #utopian-io6 years ago

images.png
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.
Screenshot (21).png
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

Sort:  

Thank you for your contribution.

  • Improve the structure of your tutorial. Markdown

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @portugalcoin!

So far this week you've reviewed 24 contributions. Keep up the good work!

Hey @yalzeee
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hi @yalzeee! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!

Thank you for this code as short as it was, I was able to run it without any problem.

I'm glad it was helpful
I had to make a post to end the series by explaining how to deploy on startup and it is brief and isn't too complicated but is totally necessaary . Glad it worked for you.

Congratulations @yalzeee! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.19
TRX 0.17
JST 0.033
BTC 64258.81
ETH 2772.25
USDT 1.00
SBD 2.65