File tree Expand file tree Collapse file tree 7 files changed +103
-0
lines changed Expand file tree Collapse file tree 7 files changed +103
-0
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,5 @@ was used to develop it.
33331 . ` code-organization ` : illustration of how to organize code in packages
3434 and modules.
35351 . ` error-handling ` : simple illustration of error handling.
36+ 1 . ` pyinstaller ` : illustration of how to use ` pyinstaller ` to create
37+ standalone executables.
Original file line number Diff line number Diff line change 1+ # virtual environment to build applications
2+ build_env /
3+
4+ # build directory
5+ build /
6+
7+ # distribution directory
8+ dist /
9+
10+ # Python cache directories
11+ __pycache__ /
Original file line number Diff line number Diff line change 1+ # PyInstaller
2+
3+ PyInstaller bundles a Python application and all its dependencies into a single
4+ package. The user can run the packaged app without installing a Python
5+ interpreter or any modules. It is very useful to minimize dependencies.
6+
7+
8+ ## What is it?
9+
10+ 1 . ` src ` : directory with a Python scripts that use the pandas library and that
11+ requires access to a CSV file.
12+ 1 . ` data.csv ` : CSV file that is used by the Python script in ` src ` .
13+ 1 . ` requirements.txt ` : file listing the Python packages that are required by
14+ the Python script in ` src ` .
15+
16+
17+ ## How to create the applications?
18+
19+ 1 . Create a virtual environment and install the required packages:
20+ ``` bash
21+ $ python -m venv build_venv
22+ $ source build_venv/bin/activate
23+ (venv)$ pip install -r requirements.txt
24+ ```
25+ 1 . Create the application:
26+ ``` bash
27+ $ pyinstaller \
28+ --onefile \
29+ --hidden-import funcs \
30+ --collect-submodules funcs \
31+ src/sum_columns.py
32+ $ pyinstaller \
33+ --onefile \
34+ --add-data data.csv:data.csv \
35+ --hidden-import funcs \
36+ --collect-submodules funcs \
37+ src/sum_columns.py
38+ ```
Original file line number Diff line number Diff line change 1+ A,B,C
2+ 1.2,2.3,4.5
3+ 2.1,3.2,5.4
4+ 3.3,5.5,9.9
Original file line number Diff line number Diff line change 1+ pyinstaller
2+ pandas
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import argparse
4+ import pathlib
5+ import sys
6+ from lib .funcs import prod_columns
7+
8+ def main ():
9+ parser = argparse .ArgumentParser ()
10+ parser .add_argument ('input_file' , nargs = '?' ,
11+ help = 'Input CSV file' )
12+ parser .add_argument ('--version' , action = 'store_true' ,
13+ help = 'Print Python version and exit' )
14+ args = parser .parse_args ()
15+ if args .version :
16+ print (sys .version )
17+ sys .exit (0 )
18+ if args .input_file is None :
19+ data_dir = pathlib .Path (__file__ ).parent
20+ prod_columns (data_dir / 'data.csv' )
21+ else :
22+ prod_columns (args .input_file )
23+
24+
25+ if __name__ == '__main__' :
26+ main ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import argparse
4+ import sys
5+ from lib .funcs import sum_columns
6+
7+ def main ():
8+ parser = argparse .ArgumentParser ()
9+ parser .add_argument ('input_file' , help = 'Input CSV file' )
10+ parser .add_argument ('--version' , action = 'store_true' ,
11+ help = 'Print Python version and exit' )
12+ args = parser .parse_args ()
13+ if args .version :
14+ print (sys .version )
15+ sys .exit (0 )
16+ sum_columns (args .input_file )
17+
18+
19+ if __name__ == '__main__' :
20+ main ()
You can’t perform that action at this time.
0 commit comments