程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python+web automated packaging exe+ configuration file

編輯:Python

introduction : Simply package a single independent .py The document is simple , But few blogs want to apply the framework . I have found many blogs that are very watery , What feeding tutorial , It's too water , Packaging is still not implemented .
This article only quotes a blog link : My idea comes from this link , Finally, I realized the function I wanted ! Link up

precondition : download pyinstaller library

Download from the Internet :pip install pyinstaller
There is no Internet to download these plug-ins : Official website for you : Poke it here Red is the plug-in name , such as zipp
Just remember to go in and modify the path https://pypi.org/project/pycparser/#files Just change it to https://pypi.org/project/zipp/#files

First 、

One 、 Generate XXX.spec file

open cmd, The path switches to pycharm Under the project directory of , Carry out orders :xxx.py That is, the file you want to package

pyi-makespec xxx.py

stay windows You can see this file in the window . Then go inside and use txt perhaps notepad++ edit ;

Two 、 edit XXX.spec file

Here is the content ! Introduce to you : In addition to the modifications, make your own modifications , Other places directly copy Just mine
What needs to be revised :
1、Analysis(['run.py'] --------- > Is the file you want to package , That is, the execution entry
2、name='run' --------- > file name , No suffix is required
3、hiddenimports = […] These are all your operations run.py Necessary dependent files . Note that the definition of dependency file is in your code, such as I wrote WEB automation , These files are files that perform operations , For example, click on , sign out , Open the web page . If it is api Automation framework , Try writing a file to execute test cases , such as unittest file , This blogger has never tried , Forgive me !
give an example :
web_ui_auto_lib.element_behavior_handlers.check_behavior_handler’, In fact, this is the path :web_ui_auto_lib/element_behavior_handlers/check_behavior_handler,check_behavior_handler Is the file name

# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['run.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=['web_ui_auto_lib.element_behavior_handlers.check_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.click_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.close_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.refresh_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.input_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.openurl_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.screenshot_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.move_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.upload_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.quit_behavior_handler',
'web_ui_auto_lib.element_behavior_handlers.point_behavior_handler'],
hookspath=[],
hooksconfig={
},
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)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='run',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )

3、 ... and 、 Opened in the first step CMD In the implementation of XXX.spec file

Enter the command :-F Is to package a single file , In fact, the import probability is only one

pyinstaller -F run.spec

Four 、 Two files will be produced in the project directory , One for dist One for build.

go in dist In file , You'll find that a XXX.exe file , We want to package file tools

I haven't finished paying attention !!!!!!!!!!!!!!!!!!!!!!!!!!!

We also need to add our configuration file ! our EXCEL where , According to the path of our configuration file , Some of our configuration files should be located in the same place as our project .
I suggest you write relative paths , Such as my : In addition to the absolute path used for the generated report , The others are relative paths

[file]
report_file_path = C:\\Temp\\Report\\
screenshot_path = .\screenshot
runstatus_file_path = C:\\Temp\\runstatus\\
file_download_path = C:\\Temp\\download
driver_file_path = .\data\chromedriver.exe
driver_name = "Chrome:chromedriver,Firefox:geckodriver"
staff_file_path = .\data\\staff.json
report_html_path = .\report
addTest_path = .\web_ui_auto_lib\
[log]
log_folder_path = .\logs
log_level = 4
[version]
versionid = v0.1

give an example :

staff_file_path = .\data\\staff.json, This file requires data Catalog , So you need to be in dist Create a new data file , And then put staff.json Throw the document in .
In a word : Put all the configuration files or drivers you need , It's all yours dist Below file , Pay attention to the hierarchical relationship written by yourself , Relative path has folder , Just create a new folder , If you don't, just throw the file , Those automatically generated files or folders don't have to be thrown away

5、 ... and 、 Last , You will run successfully !!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved