CN111258595B - 一种基于PyInstaller的python源代码封装方法 - Google Patents
一种基于PyInstaller的python源代码封装方法 Download PDFInfo
- Publication number
- CN111258595B CN111258595B CN202010175824.8A CN202010175824A CN111258595B CN 111258595 B CN111258595 B CN 111258595B CN 202010175824 A CN202010175824 A CN 202010175824A CN 111258595 B CN111258595 B CN 111258595B
- Authority
- CN
- China
- Prior art keywords
- file
- python
- pyinstaller
- script
- source code
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 20
- 238000004806 packaging method and process Methods 0.000 title claims abstract description 16
- 230000001419 dependent effect Effects 0.000 claims abstract description 5
- 230000008676 import Effects 0.000 claims description 8
- 238000005538 encapsulation Methods 0.000 claims description 5
- 238000012858 packaging process Methods 0.000 description 4
- 238000012856 packing Methods 0.000 description 3
- 241001269238 Data Species 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000009434 installation Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/61—Installation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/10—Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
- G06F21/12—Protecting executable software
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Abstract
本发明公开了一种基于PyInstaller的源代码封装方法,本发明包括以下步骤:安装用于管理python软件的pip命令,并根据pip3命令安装python;准备并检查python源文件代码;运行命令PyInstaller yourpythonscript,获取脚本运行所需要的模块和库;利用PyInstaller将脚本及其所有依赖项捆绑到一个名为yourpythonscript的可执行文件中;添加项目需要的额外文件。本发明提供了一种基于PyInstaller的python源代码封装方法,其意义在于制作可以重复使用的软件,在要部署的目标系统上,无需使用源代码,无需处理依赖,无需编译,便用户使用。此外,避免了项目源码的暴露,防止他人盗用或篡改,实现了软件安全管理。
Description
技术领域
本发明涉及软件源代码封装领域,具体涉及一种基于PyInstaller的源代码封装方法。
背景技术
软件源代码封装是指把你的应用和其依赖的组件组织在一起,以便于分发到目标系统上。客户端软件的时代,如office 97烧录成一个iso(便于刻在光盘上)就是个典型的打包的过程;互联网时代,一个java项目生成 jar,python项目生成 wheel/egg,也是打包的过程;此外,make对于C/C++项目的任务管理工具的一大主要用途就是打包。简单的应用,打包的过程可以很快,因为只需应用本身的编译和依赖处理,秒级就可以完成;但复杂的应用可能需要数个钟头。比如说,一个嵌入式软件需要用 buildroot 把 OS,dependencies及应用软件深度整合在一个可以直接烧录在硬件的 firmware 里,其 full build 可能需要几个小时。
打包的意义在于制作可以重复使用的软件,所有琐碎的活儿都在打包的时候完成了,而在要部署的目标系统上,无需使用源代码,无需处理依赖,无需编译,只要把打包好的软件安装好即可。打包的过程,实际上是一系列手工操作的合集,因此必然有相应的工具来帮助提高打包的效率。
发明内容
本发明为了克服现有技术中技术问题,提供一种基于PyInstaller的源代码封装方法。制作可以重复使用的软件,在要部署的目标系统上,无需使用源代码,无需处理依赖,无需编译,只需安装好打包完成的软件,方便用户使用。此外,避免了项目源码的暴露,防止他人盗用或篡改,实现了软件安全管理。本发明采用如下技术方案:
一种基于PyInstaller的python源代码封装方法,其特征在于包括:
1)安装用于管理python软件的pip命令,并根据pip3命令安装python;
2)准备并检查python源文件代码,保证源文件中所有的模块导入均为正确方式,将后缀为.py结尾的资源文件和项目所必须的额外文件整理分类;
3)运行命令PyInstaller yourpythonscript,来获取脚本运行所需要的模块和库,这些模块和库称为“依赖项”;具体过程为:PyInstaller在脚本中找到所有import语句,找到被导入的模块,并在其中查找import语句,以递归方式进行操作,直到获得脚本可以使用的模块的完整列表;
4)利用PyInstaller将脚本及其所有依赖项捆绑到一个名为yourpythonscript的可执行文件中;
5)添加项目需要的额外文件,使用add-data命令选项将数据文件添加到捆绑软件中,或将它们作为列表添加到规格文件yourscriptname.spec中,先为pyinstaller分析过程提供一个描述data参数值的列表,再使用规格文件;
6)经过以上操作后即可完成源代码的封装操作,打包后的可执行文件在当前目录下的dist目录下。
优选的,所述步骤4)中名为yourpythonscript的可执行文件脚本及其所有依赖项捆绑到一个文件夹中,依赖使用者选取的参数决定捆绑方式。
优选的,所述步骤5)中data文件列表是元组列表,每个元组都有两个值,两值都必须是字符串,第一个字符串指定文件或它们现在在此系统中的位置,第二个字母指定运行时包含文件的文件夹的名称。
例如,要将单个README文件添加到单文件夹应用程序的顶层,可以按如下所示修改spec文件:
a= Analysis(…
datas=[(‘src/README.txt’,‘。’)],
…
)。
有益效果:
提供了一种基于PyInstaller的python源代码封装方法,其意义在于制作可以重复使用的软件。所有琐碎的活儿都在打包的时候完成了,而在要部署的目标系统上,无需使用源代码,无需处理依赖,无需编译,只要把打包好的软件「安装」好即可,方便用户使用。此外,避免了项目源码的暴露,防止他人盗用或篡改,实现了软件安全管理。
附图说明
附图1为软件源代码封装流程示意图;
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的方法方案进行清楚、完整的描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请的实施例,本领域普通方法人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围,如方案步骤一所示:
Step1:安装用于管理python软件的pip命令
apt-get install python-pip3。
Step2:使用pip3命令安装PyInstaller:
Pip3 install pyinstaller。
Step3:准备并检查python源文件代码,保证源文件中所有的模块导入均为正确方式,将后缀为.py结尾的资源文件和项目所必须的额外文件整理分类。
Step4:运行命令PyInstaller yourpythonscript,来获取脚本运行所需要的模块和库,这些模块和库称为“依赖项”;具体过程为:PyInstaller在脚本中找到所有import语句,找到被导入的模块,并在其中查找import语句,以递归方式进行操作,直到获得脚本可以使用的模块的完整列表。
Step5:利用PyInstaller对yourscript.py文件进行封装打包,打包方式有两种,1、单文件夹模式:PyInstaller yourscript.py,2、单文件模式:PyInstaller -Fyourscript.py。
Step6:添加项目所需额外文件,利用--add-data命令选项将数据文件添加到捆绑软件中;具体命令如下: PyInstaller --add-data ‘the first string : the secondstring’ your script,;上述单引号中的两个值都必须是字符串,第一个字符串指定文件或它们现在在此系统中的位置;第二个字母指定运行时包含文件的文件夹的名称。
Step7:完成了源代码封装操作,打包后的可执行文件在当前目录下的dist目录下。
Claims (3)
1.一种基于PyInstaller的python源代码封装方法,其特征在于,包括以下步骤:
1)安装用于管理python软件的pip命令,并根据pip3命令安装PyInstaller;
2)准备并检查python源文件代码,保证源文件中所有的模块导入均为正确方式,将后缀为.py的资源文件和项目所必须的额外文件整理分类;
3)运行命令PyInstaller yourpythonscript,获取脚本运行所需要的模块和库,所述模块和库为依赖项;具体过程为:PyInstaller在脚本中找到了所有import语句,找到被导入的模块,并在其中查找import语句,以递归方式进行操作,直到获得脚本可以使用的模块的完整列表;
4)利用PyInstaller将脚本及其所有依赖项捆绑到一个名为yourpythonscript的可执行文件中;
5)添加项目需要的额外文件,使用add-data命令选项将数据文件添加到捆绑软件中,或将它们作为列表添加到规格文件yourscriptname.spec中,先为pyinstaller分析过程提供一个描述data参数值的列表,再使用规格文件;
6)经过以上操作后即可完成源代码的封装操作,打包后的可执行件在当前目录下的dist目录下。
2.根据权利要求1所述的基于PyInstaller的python源代码封装方法,其特征在于:所述步骤4)中名为yourpythonscript的可执行文件脚本及其所有依赖项捆绑到一个文件夹中。
3.根据权利要求1所述的基于PyInstaller的python源代码封装方法,其特征在于:所述步骤5)中data文件列表是元组列表,每个元组都有两个值,两值都必须是字符串,第一个字符串指定文件或它们现在在此系统中的位置,第二个字母指定运行时包含文件的文件夹的名称。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010175824.8A CN111258595B (zh) | 2020-03-13 | 2020-03-13 | 一种基于PyInstaller的python源代码封装方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010175824.8A CN111258595B (zh) | 2020-03-13 | 2020-03-13 | 一种基于PyInstaller的python源代码封装方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111258595A CN111258595A (zh) | 2020-06-09 |
CN111258595B true CN111258595B (zh) | 2023-08-01 |
Family
ID=70951441
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010175824.8A Active CN111258595B (zh) | 2020-03-13 | 2020-03-13 | 一种基于PyInstaller的python源代码封装方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111258595B (zh) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113204351B (zh) * | 2021-07-06 | 2021-10-22 | 成都菁蓉联创科技有限公司 | 一种嵌入式系统包管理方法及其使用方法 |
CN117707547A (zh) * | 2024-02-05 | 2024-03-15 | 云筑信息科技(成都)有限公司 | 一种解析java项目间引用关系的方法 |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107786644A (zh) * | 2017-10-11 | 2018-03-09 | 五八有限公司 | 渠道包的下载方法、装置及设备 |
CN108363911A (zh) * | 2018-02-11 | 2018-08-03 | 西安四叶草信息技术有限公司 | 一种Python脚本混淆、水印的方法及装置 |
CN108519874A (zh) * | 2017-02-27 | 2018-09-11 | 腾讯科技(深圳)有限公司 | Python项目包的生成方法及装置 |
CN109634592A (zh) * | 2018-12-29 | 2019-04-16 | 深圳点猫科技有限公司 | 图形化Python编程交互方法、系统及电子设备 |
CN109670299A (zh) * | 2018-12-29 | 2019-04-23 | 深圳点猫科技有限公司 | 一种创建Python沙盒环境的方法及电子设备 |
CN109756570A (zh) * | 2018-12-29 | 2019-05-14 | 深圳点猫科技有限公司 | 一种实现定制pypi镜像服务器的方法及电子设备 |
CN109800000A (zh) * | 2018-12-28 | 2019-05-24 | 深圳竹云科技有限公司 | 一种基于python的自动化测试环境部署的方法 |
WO2019232948A1 (zh) * | 2018-06-05 | 2019-12-12 | 平安科技(深圳)有限公司 | 监控邮件自动发送方法、系统、计算机设备和存储介质 |
CN110659022A (zh) * | 2019-08-19 | 2020-01-07 | 浙江邦盛科技有限公司 | 一种基于Java自动调用Python脚本的方法 |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
FR2934697B1 (fr) * | 2008-07-29 | 2010-09-10 | Thales Sa | Procede et systeme permettant de securiser un logiciel |
CN103440156B (zh) * | 2013-08-15 | 2016-11-09 | 国云科技股份有限公司 | 一种能用于多种系统下的Linux软件包制作方法 |
CN110688632A (zh) * | 2019-09-06 | 2020-01-14 | 中国平安财产保险股份有限公司 | 应用程序的登录方法、装置、设备及存储介质 |
-
2020
- 2020-03-13 CN CN202010175824.8A patent/CN111258595B/zh active Active
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108519874A (zh) * | 2017-02-27 | 2018-09-11 | 腾讯科技(深圳)有限公司 | Python项目包的生成方法及装置 |
CN107786644A (zh) * | 2017-10-11 | 2018-03-09 | 五八有限公司 | 渠道包的下载方法、装置及设备 |
CN108363911A (zh) * | 2018-02-11 | 2018-08-03 | 西安四叶草信息技术有限公司 | 一种Python脚本混淆、水印的方法及装置 |
WO2019232948A1 (zh) * | 2018-06-05 | 2019-12-12 | 平安科技(深圳)有限公司 | 监控邮件自动发送方法、系统、计算机设备和存储介质 |
CN109800000A (zh) * | 2018-12-28 | 2019-05-24 | 深圳竹云科技有限公司 | 一种基于python的自动化测试环境部署的方法 |
CN109634592A (zh) * | 2018-12-29 | 2019-04-16 | 深圳点猫科技有限公司 | 图形化Python编程交互方法、系统及电子设备 |
CN109670299A (zh) * | 2018-12-29 | 2019-04-23 | 深圳点猫科技有限公司 | 一种创建Python沙盒环境的方法及电子设备 |
CN109756570A (zh) * | 2018-12-29 | 2019-05-14 | 深圳点猫科技有限公司 | 一种实现定制pypi镜像服务器的方法及电子设备 |
CN110659022A (zh) * | 2019-08-19 | 2020-01-07 | 浙江邦盛科技有限公司 | 一种基于Java自动调用Python脚本的方法 |
Also Published As
Publication number | Publication date |
---|---|
CN111258595A (zh) | 2020-06-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8918777B2 (en) | Schema specification to improve product consumability on installation, configuration, and/or un-installation activity | |
CN111258595B (zh) | 一种基于PyInstaller的python源代码封装方法 | |
US8352926B2 (en) | Method and apparatus for a cross-platform translator from VB.net to java | |
US7565364B1 (en) | Annotation processor discovery | |
EP4095677A1 (en) | Extensible data transformation authoring and validation system | |
US20080127070A1 (en) | System and method for instantiating an interface or abstract class in application code | |
EP1530127A2 (en) | Resource manifest for providing language-neutral and language-specific resource location services | |
CN103324474B (zh) | 基于Linux操作系统跨体系构造ISO的方法及模块 | |
Seery | CppTransport: a platform to automate calculation of inflationary correlation functions | |
US20070050380A1 (en) | Nullable and late binding | |
US9690617B2 (en) | Adjustment of a task execution plan at runtime | |
Malm et al. | APP: an Automated Proteomics Pipeline for the analysis of mass spectrometry data based on multiple open access tools | |
CN104391733A (zh) | 一种依据依赖关系动态编译软件包的方法 | |
Bauml et al. | Automated versioning in OSGi: A mechanism for component software consistency guarantee | |
Bartusch et al. | Reproducible scientific workflows for high performance and cloud computing | |
CN116185391A (zh) | 应用程序编程接口生成方法、装置、设备及存储介质 | |
US20140143761A1 (en) | Method and system for database conversion | |
EP2109040A2 (en) | Software build process using meta data for mapping the input to the output of a software module | |
Rowe et al. | Rotor: First steps towards a refactoring tool for ocaml | |
CN111079160A (zh) | 权限管理框架搭建方法和系统 | |
US8135943B1 (en) | Method, apparatus, and computer-readable medium for generating a dispatching function | |
Li et al. | Enhancing LLM-Based Coding Tools through Native Integration of IDE-Derived Static Context | |
Kurs et al. | Nextflow Workbench Documentation Booklet | |
Marchioni | JBoss AS 7 Development | |
Beuks | Building a dependency graph from Java source code files |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Address after: 250000 No. 2877 Kehang Road, Suncun Town, Jinan High-tech District, Shandong Province Applicant after: Chaoyue Technology Co.,Ltd. Address before: 250014 no.2877 Kehang Road, Suncun Town, high tech Zone, Jinan City, Shandong Province Applicant before: SHANDONG CHAOYUE DATA CONTROL ELECTRONICS Co.,Ltd. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant |