Py Python How to package files into exe

Installation pyinstaller

Open cmd window, enter PIP install pyinstaller , command line output successfully indicates success.

 

Generate exe files

A single file py

Py file in the directory, open cmd window, enter pyinstall -F XXX.py , the implementation of successful, will generate a dist folder in the current directory, XXX.exe file in this folder.

Add version information :

After installing pyinstaller, we will get two aids, pyi-grab_version and pyi-set_version.

1. pyi-grab_version create a template file version information, first find a XXX.exe tool version information, open cmd window in this directory, enter pyi-grab_version XXX.exe , after the successful implementation, will get in this directory file_version_info.txt a file, this is what we want the file version information template file.

2. With the template file, we need to modify the contents inside, into our version of the content they want, it is best to open with nopad ++.

3. Add the version information when packaging.

A method is also not packaged into the exe file py

pyinstaller -F --version--file file_version_info.txt XXX.py

The second method has been packaged exe

pyi-set_version file_version_info.txt XXX.exe

 

Second, multiple py files

1, as far as possible all py file to be executed in a large folder (which allows multiple folders)

2, a command line input PYI-makespec the main.py (the main.py inlet Python program file py)

3, now swells into a folder and file main.spec two folders

4, edit main.spec file, find a = Analysis (), to modify the first argument, there must be a list of file py

a = Analysis(['pin.py'],
             pathex=['F:\\python_work\\pytest\\pin'],
             binaries=[],
             dates = []
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

 

If you use the other py file py joined path to the appropriate file in the first list which, if it is at the same level directory, direct write the file name, if not under the same file, write the full path.

a = Analysis(['pin.py', 'cursor_control.py'],
             pathex=['F:\\python_work\\pytest\\pin'],
             binaries=[],
             dates = []
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

 

If you use a non-py file needs to be packaged, then find a list of datas, non-py file path and file name of the folder written in the tuple.

E.g:

datas = [('C:\\project\\test\\images','images'),('C:\\project\\test\\EventLogs','EventLogs')]

 

dates:

The first parameter is the path of non-py file type in Python

The second argument is non-py file saving this resource folder name, and path to the folder with the same name.

Guess you like

Origin www.cnblogs.com/smart-zihan/p/11881172.html