Command Line Interface (CLI)
A command-line interface is a tool through which the user can interact with a program. Users can run the necessary commands and pass system arguments to the code and the response is generated as per written in the program.
Advantages of Command Line Interface:
- It requires fewer resources.
- Easy to Use.
- Available in all operating systems.
Pyinstaller is used to merge all the code of python (single or multiple), all installed libraries and dependencies into one single file. Using this, the user can run the program from the packaged code without the need for any library or any modules used in the code.
If a user sends that packaged app to other users and that user does not have any dependencies installed in its system(not even python) even then the user can run that packaged app.
To install Pyinstaller through pip:
Pyinstaller requires python script to make the packaged app. The code can be grouped into a single folder or a single file. It automatically detects the libraries or other methods that have used in python script using the import method to merge in a single file. However, it is not a cross-compiler. To make an app for the Windows app, the pyinstaller commands need to run on the window operating system and the same for the Linux case also.
Pyinstaller –onefile /path/to/yourscript.py
This will generate a single file in a directory named dist. This file can be run using the command-line interface.
Example – To make a CSV file reader –
with open(fileLocation,’rt’)as f:
data = csv.reader(f)
for row in data:
from Helpers import *
csvFileLocation = sys.argv csvFileData = readCsvFile(csvFileLocation)
Then run pyinstaller command –
pyinstaller –onefile csvReader.py
It will generate a packaged app in the dist folder.
Note – The generate packaged app will work only for the operating system from which it is generated.
Now, open command line –
- cd packaged app directory
- For Ubuntu – ./csvReader /home/User/Desktop/csvFile.csv
- For Windows – csvReader D:/test/csvFile.csv
[‘S.No.’, ‘RollNo’, ‘Name’]
[‘1’, ‘Webner1’, ‘Test User1’]
[‘2’, ‘Webner2’, ‘Test User2’]