『Python学习笔记』Pyinstaller打包python程序遇到的问题(Win&Linux)+Cython编译动态库+PyArmor加密! 阳光穿透心脏的1/2处 2022-09-02 11:53 8553阅读 0赞 <table> <tbody> <tr> <td><font>Pyinstaller打包python程序遇到的问题(Win&Linux)+Cython编译动态库+PyArmor加密!</font> </td> </tr> </tbody> </table> ### 文章目录 ### * 一. Pyinstaller简要介绍 * 二. Pyinstaller打包的一些问题 * * 2.1. 打包cpca模块无法解析 * 2.2. 打包jieba模块无法解析 * 2.3. 安装pyzbar模块 * 2.4. 打包Tranformer模块的问题 * 2.5. 打包过程中一些库文件缺失(重要)以及打包性能 * 2.6. 打包有参数传递的程序 * 2.7. Pyinstaller打包过程中加密 * 三. Win和Linux系统下打包 * * 3.1. Linux系统下对程序进行打包 * 3.2. Win系统下对程序进行打包 * 3.3. 查看Linux系统是Centos还是Ubuntu * 四. Cython编辑Python为动态库 * 五. PyArmor加密技术 * 六. 参考文章 # 一. Pyinstaller简要介绍 # > * `PyInstaller`是一个 **能将`Python`程序转换成单个可执行文件的程序**,操作系统支持`Windows, Linux, Mac OS X, Solaris和AIX`。`PyInstaller`库是第三方库,使用时需要额外安装。 ![449ea920083e41fe934efbcf49ad3973.png][] > * 安装`Pyinstaller`包,命令如下: pip install pyinstaller # Pyinstaller版本 (info) devinzhang@kaifang info_extractor_bei % pyinstaller -v 4.4 > * 一些常用的功能参数,官方手册可参考:[https://pyinstaller.readthedocs.io/en/stable/][https_pyinstaller.readthedocs.io_en_stable] <table> <thead> <tr> <th>参数</th> <th>含义</th> </tr> </thead> <tbody> <tr> <td><code>-F</code>(重要)</td> <td>生成结果是一个<code>exe</code>程序,所有第三方依赖库和其他资源都被打包进该<code>exe</code>程序中 (<code>-F</code>会压缩包,占用空间小,但是执行的时候需要先解压,所以启动速度慢,不加<code>-F</code>启动快,但是占用空间大)</td> </tr> <tr> <td><code>-distpath</code></td> <td>指定打包后的程序存放目录,默认存放在当前目录下的<code>dist</code>目录</td> </tr> <tr> <td><code>-workpath</code></td> <td>指定编译过程中临时文件的存放位置</td> </tr> <tr> <td><code>-D</code></td> <td>生成结果是一个包含<code>exe</code>程序的目录,所有第三方依赖库和其他资源和<code>exe</code>程序位于同一目录下(<strong>默认条件</strong>就是这个)</td> </tr> <tr> <td><code>-i</code></td> <td>指定可执行文件的图标(只对<code>windows</code>系统有效)</td> </tr> <tr> <td><code>-p</code></td> <td>指定可执行文件依赖的包和模块,如 <code>-p "/usr/local/lib/python3.5/dist-packages"</code></td> </tr> <tr> <td><code>-d</code></td> <td>编译为<code>debug</code>模式,获取运行中的日志信息</td> </tr> <tr> <td><code>-clean</code></td> <td>在构建之前,清理<code>PyInstaller</code>缓存并删除临时文件。即清空<code>build</code>目录里的文件</td> </tr> <tr> <td><code>-c</code></td> <td>使用控制台,<strong>默认模式</strong></td> </tr> <tr> <td><code>-w</code>(重要)</td> <td>不使用控制台</td> </tr> <tr> <td><code>-version-file</code></td> <td>添加版本信息</td> </tr> <tr> <td><code>-y</code>(重要)</td> <td>如果<code>dist</code>文件夹内已经存在生成文件,则不询问用户直接覆盖</td> </tr> <tr> <td><code>--key</code>(重要)</td> <td><font>对打包进行加密,则会提示安装 <code>pip install tinyaes</code>,如<code>pyinstaller -F --key '12345678' --clean main.py</code></font></td> </tr> <tr> <td><code>--add-data</code>(重要)</td> <td>要添加到可执行文件的其他非二进制文件或文件夹。使用路径分隔符是特定于平台的<code>os.pathsep</code>(<code>;在 Windows 和:大多数 unix 系统上</code>)。此选项可以多次使用。</td> </tr> <tr> <td><code>--copy-metadata</code>(重要)</td> <td><font>复制指定包的元数据。此选项可以多次使用。</font></td> </tr> </tbody> </table> > * 使用 PyInstaller(官方手册):[https://pyinstaller.readthedocs.io/en/stable/usage.html][https_pyinstaller.readthedocs.io_en_stable_usage.html] # 二. Pyinstaller打包的一些问题 # ## 2.1. 打包cpca模块无法解析 ## > * **打包前需要引入`cpca`相关模块,否则会异常报错**。 # 导入cpca模块时,需要导入该模块,否则会异常报错 import pandas._libs.tslibs.base import cpca > * 打包命令中添加相关指令,以免打包后的`exe`找不到相关资源,如下: # 我的mac pyinstaller -F -w main.py \ --add-data "/Users/devinzhang/miniconda3/envs/info/lib/python3.7/site-packages/cpca/resources:cpca/resources" \ --add-data "./config/*:./config" # 我的centos202 pyinstaller -F -w main.py --add-data "/opt/conda/envs/info/lib/python3.7/site-packages/cpca/resources:cpca/resources" --add-data "./config/*:./config" # 我的centos202 zhonghai(加密和压缩) pyinstaller --key '12345678' -F -y main1.py --copy-metadata tqdm \ --copy-metadata regex --copy-metadata sacremoses --copy-metadata requests \ --copy-metadata packaging --copy-metadata filelock --copy-metadata numpy \ --copy-metadata tokenizers --copy-metadata importlib_metadata \ --add-data "./model_rbt3/*:./model_rbt3" # 实验发现:程序代码如果直接读取目录的话,打包不行,如果读取文件的话是可以的,也不建议打包模型文件, # 方便后期更新模型。这样不需要重新打包。 # 我的centos203 pyinstaller -F -y main.py \ --add-data "/data/aibox/miniconda3/envs/info/lib/python3.7/site-packages/cpca/resources:cpca/resources" \ --add-data "./config/*:./config" # 我的ubuntu pyinstaller -F -w main.py \ --add-data "/dataNew/kaifang/miniconda3/envs/info/lib/python3.7/site-packages/cpca/resources:cpca/resources" \ --add-data "./config/*:./config" > * **为什么要使用** `--add-data`:**主要因为:程序里文件格式有很多种**。 > * ①源代码`.py` > * ②图片格式 `.png .jpg .ico` 等 > * ③配置文件 `.ini .json .xml .txt`等 > * ④其他可执行文件 `.bin .exe`等 > * ⑤模型文件 `.pth` 等 > * ⑥说明文档 `.txt .md`等 > * **注意:** `Pyinstaller`在打包的过程中,除了`.py`之外,其他格式不会编译。除了`.py`之外,其他格式若要打包进去,需要使用 `--add-data` 处理,或者手动拷贝(嫌麻烦,你每次都能记住)。 > * 如何使用 `--add-data`,用法如下: pyinstaller x.py --add-data="源地址;目标地址"。 # 注意上面这里windows以;分割,linux以:分割 > * **注意上面这里`windows`以`;`分割,`linux`以`:`分割。**例如:将 `config` 目录的所有文件打包到目标的 `config` 文件夹(不存在会自动创建)下 pyinstaller x.py --add-data "./config/*:./config" # mac和linux系统中 pyinstaller x.py --add-data "./config/*;./config" # windows系统中 > * 可使用多次 `--add-data` pyinstaller x.py -i "res\logo.ico" --add-data=".\*.txt;." --add-data=".\*.json;." --add-data="res\*.*;.\res" --add-data="dist\models\*.*;.\models" ## 2.2. 打包jieba模块无法解析 ## > * 缺少`dict.txt`,打包项目是成功的,但是运行项目时就会提示缺少文件 > * 这是因为`jieba`会到默认目录寻找`dict.txt`,我们只需要将默认目录改到指定目录就行了,这里以打包生成的exe所在目录为例 import jieba jieba.set_dictionary(".\dict.txt") jieba.initialize() > * 这样打包生成的`exe`执行时就会在当前目录寻找`dict.txt`。 > * 注意:在`import`了`jieba`后就要设置目录,不然还是会提示缺少文件 > * **注意**:这每次运行jieba分词时程序会先检查是否存在jieba.cache这个文件。如果存在直接使用这个文件中的信息,否则重新根据词典建树并生成新的jieba.cache。所以每次在使用新的词典之前需要把这个文件删除。会在`/tmp`目录下生成。 import platform import getpass op_system = platform.system() # 获取操作系统类型,windows、linux等 if op_system == "Linux": path_cache = "/tmp/" for del_file in os.listdir(path_cache): if del_file.startswith("jieba."): os.remove(os.path.join(path_cache, del_file)) print("=========删除Linux中的jieba.cache缓存!=========") else: user_name = getpass.getuser() # 获取当前用户名 path_cache = os.path.join("C:\\Users\\", user_name, "\\AppData\Local\Temp\\") for del_file in os.listdir(path_cache): if del_file.startswith("jieba."): os.remove(os.path.join(path_cache, del_file)) print("=========删除Windows中的jieba.cache缓存!=========") > * 也可以参考本博客:[https://blog.csdn.net/qq\_44703886/article/details/109763756][https_blog.csdn.net_qq_44703886_article_details_109763756] ## 2.3. 安装pyzbar模块 ## > * `windows`下安装 `pyahocorasick` 失败 > * 解决方法: conda config --add channels conda-forge conda install pyahocorasick 2、ubuntu部署打包 sudo apt-get install libzbar-dev pip install pyzbar 3、centos部署打包 yum install python-devel yum install zbar-devel pip install pyzbar ## 2.4. 打包Tranformer模块的问题 ## > * <font color=>最近有一个项目在使用到了transformers这个包,因为加密需要所以使用了pyinstaller对程序打了包,程序执行的时候发现了以下报错: Traceback (most recent call last): File "transformers/utils/versions.py", line 105, in require_version File "importlib_metadata/__init__.py", line 994, in version File "importlib_metadata/__init__.py", line 967, in distribution File "importlib_metadata/__init__.py", line 561, in from_name importlib_metadata.PackageNotFoundError: No package metadata was found for XXX During handling of the above exception, another exception occurred: Traceback (most recent call last): File "service/server.py", line 6, in <module> File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "model/tagging/infer_handler.py", line 1, in <module> File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "transformers/__init__.py", line 43, in <module> File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "transformers/dependency_versions_check.py", line 41, in <module> File "transformers/utils/versions.py", line 120, in require_version_core File "transformers/utils/versions.py", line 108, in require_version importlib_metadata.PackageNotFoundError: No package metadata was found for The 'XXX' distribution was not found and is required by this application. Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git master > * **解决方法:** ![watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16][] > * 重点的部分我进行了加粗,参考原帖的思路为采用修改 xxx.spec (pyinstall生成的打包文件)解决这个问题: > * ① **找到需要使用copy\_metadata方法告知pyinstaller需要添加的数据文件,在你程序对应的python环境中查看需要拷贝的数据文件的包有哪些** from transformers.dependency_versions_check import pkgs_to_check_at_runtime print(pkgs_to_check_at_runtime) > * **输出结果:** ['python', 'tqdm', 'regex', 'sacremoses', 'requests', 'packaging', 'filelock', 'numpy', 'tokenizers', 'importlib_metadata'] > * **② 修改`.spec`文件:** ... from PyInstaller.utils.hooks import collect_data_files, copy_metadata ... # tqdm issue for https://github.com/pyinstaller/pyinstaller/discussions/6033 datas = copy_metadata('tqdm') datas += copy_metadata('torch') datas += copy_metadata('regex') datas += copy_metadata('sacremoses') datas += copy_metadata('requests') datas += copy_metadata('packaging') datas += copy_metadata('filelock') datas += copy_metadata('numpy') datas += copy_metadata('tokenizers') datas += copy_metadata('importlib_metadata') ... a = Analysis(... datas=datas, ...) ... > * **这里我使用的是第1种方式,命令如下:** pyinstaller --key '12345678' -D -y main1.py --copy-metadata tqdm \ --copy-metadata regex --copy-metadata sacremoses --copy-metadata requests \ --copy-metadata packaging --copy-metadata filelock --copy-metadata numpy \ --copy-metadata tokenizers --copy-metadata importlib_metadata > * pyinstaller打包含有transformers依赖程序时出现PackageNotFoundError: [https://segmentfault.com/a/1190000040725937][https_segmentfault.com_a_1190000040725937] > * [https://github.com/pyinstaller/pyinstaller/discussions/6033][https_github.com_pyinstaller_pyinstaller_discussions_6033] ## 2.5. 打包过程中一些库文件缺失(重要)以及打包性能 ## > * **这里以`windows`系统中打包`sklearn`包的时候出现缺少`vcomp140.dll`为例,我们正常打包成文件夹。** > * 打包的过程中经常出现没有文件没有找到,比如windows系统中打包vcomp140.dll库没有找到,我们首先在系统中找一下该文件,或者搜索一下,把该文件复制粘贴到Pyinstaller导出的dist目录下。重新执行可执行文件。 ./dist/main/main > * 这个时候又报错显示,**没有找到`module`**,**这里要用到`-hidden-import`命令把缺失模组导进去。** pyinstaller -D main.py -hidden-import > * 不要忘记把`vcomp140.dll`粘贴到`dist`目录下,最后成功运行。 > * **注意**:每次打包都要复制`vcomp140.dll`到`dist`目录下,很麻烦。这里我们把`vcomp140.dll`复制到项目的目录下,直接进行打包。 pyinstaller -D main.py vcomp140.dll -hidden-import > * 执行的过程中出现问题没关系,删除掉`vcomp140.dll`,再次运行,就能成功了,把`vcomp140.dll`直接打包到文件里去了。 pyinstaller -D main.py vcomp140.dll -hidden-import > * **文件打包出来提及较大,用-F打包成单个可执行文件(体积较小),但是每次启动都需要解压,启动速度慢,可以按照自己的需求对项目进行打包。** ## 2.6. 打包有参数传递的程序 ## > * 参数传递:常见的就是 `sys.argv`还有`argparse`(这个库不是内置的,需要`pip install argparse`),前者功能比较简单,能提供的有限,后者虽然不是内置的,需要安装,但是确实功能比较强大。 # 只有三个参数 id(str) 实验类别序号 continue_transfor(str) 是否继续传递 data(json) 实验数据 import argparse # 这里的描述会出现在 usage下方 表明这个程序的作用是什么 parser = argparse.ArgumentParser(description='The input and output directories for the json file') parser.add_argument('--input', type=str, default='./dataset', help='The input directory for the json file') parser.add_argument('--output', type=str, default='./results', help='The output directory for the json file') parser.add_argument('--endpoint', type=str, default='127.0.0.1:9900') parser.add_argument('--batch_size', type=int, default="200") parser.add_argument('--task_type', type=int, default=0, choices=[0, 1, 3]) parser.add_argument('--qg_multi', action='store_true') args = parser.parse_args() input, output = args.input, args.output > * 打包完运行程序是这样的: ./dist/main --input "../dataset" ## 2.7. Pyinstaller打包过程中加密 ## > * 打包过程中指定密码来增加反编译难度:`pyinstaller` 命令里得 `--key` 用于加密`Python`字节码的密钥,来增加反编译的难度。 > * 需要安装`tinyaes`,那么输入 `pip install tinyaes` 安装。 pip install tinyaes -i https://pypi.tuna.tsinghua.edu.cn/simple # 使用清华源 pyinstaller -F --key '12345678' --clean main.py # 三. Win和Linux系统下打包 # > * 下面注意源地址和目标地址之间:windows以;分割,linux以:分割 ## 3.1. Linux系统下对程序进行打包 ## # 注意win系统下去掉-w pyinstaller -F -w main.py ^ --add-data "/data/aibox/miniconda3/envs/info/lib/python3.7/site-packages/cpca/resources:cpca/resources" ^ --add-data "./config/*:./config" ## 3.2. Win系统下对程序进行打包 ## # 注意win系统下去掉-w pyinstaller -F -w main.py ^ --add-data "C:\Users\dtwave-1\miniconda3\envs\info\Lib\site-packages\cpca\resources;cpca\resources" ^ --add-data ".\config\*;.\config" > * 若按照和linux系统一样的方式进行操作,执行exe文件会进行死机状态,显示:`error: unrecognized arguments: --multiprocessing-fork 1448` > * 可以参考这里pyinstaller官网声明:[https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing][https_github.com_pyinstaller_pyinstaller_wiki_Recipe-Multiprocessing] > * Python多处理抛出argparse和pyins错误:[https://www.cnpython.com/qa/212150][https_www.cnpython.com_qa_212150] > * argparse和pyinstaller引发的错误:[https://blog.csdn.net/weixin\_42990464/article/details/117567235][https_blog.csdn.net_weixin_42990464_article_details_117567235] ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FiYzEzNTI2MjIyMTYw_size_16_color_FFFFFF_t_70][] > * 在`if __name__ == '__main__':`下面添加如下的语法: mp.freeze_support() # 这句话的目的是防止在windows下和linux系统下生成可执行文件报错的问题。 > * 深入理解可以参考multiprocessing.freeze\_support()介绍:[https://blog.csdn.net/Owen\_goodman/article/details/115521388][https_blog.csdn.net_Owen_goodman_article_details_115521388] > * Python使用multiprocessing实现多进程:[https://blog.csdn.net/Owen\_goodman/article/details/115478298?spm=1001.2014.3001.5501][https_blog.csdn.net_Owen_goodman_article_details_115478298_spm_1001.2014.3001.5501] ## 3.3. 查看Linux系统是Centos还是Ubuntu ## # ubuntu默认是可以执行lsb_release命令的 (info) kaifang@ubuntu:/dataNew/kaifang$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.5 LTS Release: 18.04 Codename: bionic # centos需要安装 (base) [deploy@node2 ~]$ lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.2.1511 (Core) Release: 7.2.1511 Codename: Core # 执行lsb_release -a 命令存在表示为ubuntu系统 cat /etc/redhat-release 文件存在为centos # 四. Cython编辑Python为动态库 # > * **该编辑方法会逐个遍历项目下的所有.py文件进行编译动态库。具体过程如下:** > * **①. 修改原来的`main.pu文件为main1.py`具体如下:** > * **②. 新建一个`main.py`文件,内容如下,只需要`导入main1`。** # !/usr/bin/env python # -*- encoding: utf-8 -*- """===================================== @author : kaifang zhang @time : 2021/9/28 2:35 下午 @contact: kaifang.zkf@dtwave-inc.com =====================================""" import argparse from main1 import read_write_file if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--input_dir', type=str, default=r'./text', help='directory of the input file') parser.add_argument('--output_file', type=str, default=r'./keywords_freq.txt', help='path of the output file') args = parser.parse_args() input_dir, output_file = args.input_dir, args.output_file read_write_file(input_dir, output_file) print("%%%%%%%%%%%%%%% 评价短语成功写入到文件{}中了!%%%%%%%%%%%%%%".format(output_file)) > * **③. 在项目当前环境下新建`setup.py`,该文件一会用来执行编译动态库;** # !/usr/bin/env python # -*- encoding: utf-8 -*- """===================================== @author : kaifang zhang @time : 2021/9/28 2:20 下午 @contact: kaifang.zkf@dtwave-inc.com =====================================""" """ 执行前提: 系统安装python-devel 和 gcc Python安装cython 编译某个文件夹: python py2so.py BigoModel 生成结果: 目录 build 下 生成完成后: 启动文件还需要py/pyc担当,须将启动的py/pyc拷贝到编译目录并删除so文件 """ __author__ = 'devinzhang' import sys, os, shutil, time from distutils.core import setup from Cython.Build import cythonize starttime = time.time() setupfile = os.path.join(os.path.abspath('.'), __file__) def getpy(basepath=os.path.abspath('.'), parentpath='', name='', build_dir="build", excepts=(), copyOther=False, delC=False): """ 获取py文件的路径 :param basepath: 根路径 :param parentpath: 父路径 :param name: 文件/夹 :param excepts: 排除文件 :param copy: 是否copy其他文件 :return: py文件的迭代器 """ fullpath = os.path.join(basepath, parentpath, name) for fname in os.listdir(fullpath): ffile = os.path.join(fullpath, fname) if os.path.isdir(ffile) and ffile != os.path.join(basepath, build_dir) and not fname.startswith('.'): for f in getpy(basepath, os.path.join(parentpath, name), fname, build_dir, excepts, copyOther, delC): yield f elif os.path.isfile(ffile): # print("\t", basepath, parentpath, name, ffile) ext = os.path.splitext(fname)[1] if ext == ".c": if delC and os.stat(ffile).st_mtime > starttime: os.remove(ffile) elif ffile not in excepts and ext not in ('.pyc', '.pyx'): # print("\t\t", basepath, parentpath, name, ffile) if ext in ('.py', '.pyx') and not fname.startswith('__'): yield os.path.join(parentpath, name, fname) elif copyOther: dstdir = os.path.join(basepath, build_dir, parentpath, name) if not os.path.isdir(dstdir): os.makedirs(dstdir) shutil.copyfile(ffile, os.path.join(dstdir, fname)) else: pass if __name__ == "__main__": currdir = os.path.abspath('.') parentpath = sys.argv[1] if len(sys.argv) > 1 else "." currdir, parentpath = os.path.split(currdir if parentpath == "." else os.path.abspath(parentpath)) build_dir = os.path.join(parentpath, "build") build_tmp_dir = os.path.join(build_dir, "temp") print("start:", currdir, parentpath, build_dir) os.chdir(currdir) try: # 获取py列表 module_list = list(getpy(basepath=currdir, parentpath=parentpath, build_dir=build_dir, excepts=(setupfile))) print(module_list) setup(ext_modules=cythonize(module_list, compiler_directives={ 'language_level': "3"}), script_args=["build_ext", "-b", build_dir, "-t", build_tmp_dir]) module_list = list( getpy(basepath=currdir, parentpath=parentpath, build_dir=build_dir, excepts=(setupfile), copyOther=True)) except Exception as ex: print("error! ", ex) finally: print("cleaning...") module_list = list( getpy(basepath=currdir, parentpath=parentpath, build_dir=build_dir, excepts=(setupfile), delC=True)) if os.path.exists(build_tmp_dir): shutil.rmtree(build_tmp_dir) print("complate! time:", time.time() - starttime, 's') > * **④. 执行setup.py文件** (zhonghai) [deploy@node1 zhonghai]$ python setup.py ./ # Compiling zhonghai/ner.py because it changed. # Compiling zhonghai/main.py because it changed. # Compiling zhonghai/main1.py because it changed. # [1/3] Cythonizing zhonghai/main.py # [2/3] Cythonizing zhonghai/main1.py # [3/3] Cythonizing zhonghai/ner.py # running build_ext # building 'ner' extension # creating zhonghai/build/temp # creating zhonghai/build/temp/zhonghai # gcc -pthread -B /opt/conda/envs/zhonghai/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/envs/zhonghai/include/python3.7m -c zhonghai/ner.c -o zhonghai/build/temp/zhonghai/ner.o # gcc -pthread -shared -B /opt/conda/envs/zhonghai/compiler_compat -L/opt/conda/envs/zhonghai/lib -Wl,-rpath=/opt/conda/envs/zhonghai/lib -Wl,--no-as-needed -Wl,--sysroot=/ zhonghai/build/temp/zhonghai/ner.o -o zhonghai/build/ner.cpython-37m-x86_64-linux-gnu.so # building 'main' extension # gcc -pthread -B /opt/conda/envs/zhonghai/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/envs/zhonghai/include/python3.7m -c zhonghai/main.c -o zhonghai/build/temp/zhonghai/main.o # gcc -pthread -shared -B /opt/conda/envs/zhonghai/compiler_compat -L/opt/conda/envs/zhonghai/lib -Wl,-rpath=/opt/conda/envs/zhonghai/lib -Wl,--no-as-needed -Wl,--sysroot=/ zhonghai/build/temp/zhonghai/main.o -o zhonghai/build/main.cpython-37m-x86_64-linux-gnu.so # building 'main1' extension # gcc -pthread -B /opt/conda/envs/zhonghai/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/envs/zhonghai/include/python3.7m -c zhonghai/main1.c -o zhonghai/build/temp/zhonghai/main1.o # gcc -pthread -shared -B /opt/conda/envs/zhonghai/compiler_compat -L/opt/conda/envs/zhonghai/lib -Wl,-rpath=/opt/conda/envs/zhonghai/lib -Wl,--no-as-needed -Wl,--sysroot=/ zhonghai/build/temp/zhonghai/main1.o -o zhonghai/build/main1.cpython-37m-x86_64-linux-gnu.so # cleaning... # complate! time: 8.449138402938843 s > * 执行完可以得到如下文件,这个时候需要把main放进build目录下,以及其他依赖的文件也放进来。 ![watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16 1][]![watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16 2][] # 五. PyArmor加密技术 # > * 加密:[http://pyarmor.dashingsoft.com/index-zh.html\#quick-start][http_pyarmor.dashingsoft.com_index-zh.html_quick-start] # 六. 参考文章 # > * pyinstaller 系列之五:使用 `--add-data` 打包额外资源。[https://blog.csdn.net/u012219045/article/details/114841287][https_blog.csdn.net_u012219045_article_details_114841287] > * pyinstaller系列之二:去掉命令行,指定密码来增加反编译难度:[https://blog.csdn.net/u012219045/article/details/112259317][https_blog.csdn.net_u012219045_article_details_112259317] > * pyinstaller系列之四:如何设置打包出来的文件的版本信息。[https://blog.csdn.net/u012219045/article/details/113977724][https_blog.csdn.net_u012219045_article_details_113977724] > * Pyinstaller打包jieba项目相关解决方案:[https://blog.csdn.net/sinat\_34200786/article/details/79715236][https_blog.csdn.net_sinat_34200786_article_details_79715236] > * python地址解析cpca模块打包后无法解析的问题:[https://blog.csdn.net/a645328869/article/details/114059438][https_blog.csdn.net_a645328869_article_details_114059438] > * pyinstaller打包后运行提示找不到模块:[https://www.shuzhiduo.com/A/GBJrvaWWJ0/][https_www.shuzhiduo.com_A_GBJrvaWWJ0] > * python打包含有参数传递的exe程序:[https://blog.csdn.net/Castlehe/article/details/107952649][https_blog.csdn.net_Castlehe_article_details_107952649] > * pyinstaller打包经验分享以及一些错误解决方法:[https://www.bilibili.com/video/BV1bp4y1D7Dg?from=search&seid=14902449668691206456&spm\_id\_from=333.337.0.0][https_www.bilibili.com_video_BV1bp4y1D7Dg_from_search_seid_14902449668691206456_spm_id_from_333.337.0.0] [449ea920083e41fe934efbcf49ad3973.png]: /images/20220829/5216f7935be74fa09575ac238ac2c2bc.png [https_pyinstaller.readthedocs.io_en_stable]: https://pyinstaller.readthedocs.io/en/stable/ [https_pyinstaller.readthedocs.io_en_stable_usage.html]: https://pyinstaller.readthedocs.io/en/stable/usage.html [https_blog.csdn.net_qq_44703886_article_details_109763756]: https://blog.csdn.net/qq_44703886/article/details/109763756 [watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16]: /images/20220829/4b818082aa984035aa7655e7f795a815.png [https_segmentfault.com_a_1190000040725937]: https://segmentfault.com/a/1190000040725937 [https_github.com_pyinstaller_pyinstaller_discussions_6033]: https://github.com/pyinstaller/pyinstaller/discussions/6033 [https_github.com_pyinstaller_pyinstaller_wiki_Recipe-Multiprocessing]: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing [https_www.cnpython.com_qa_212150]: https://www.cnpython.com/qa/212150 [https_blog.csdn.net_weixin_42990464_article_details_117567235]: https://blog.csdn.net/weixin_42990464/article/details/117567235 [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FiYzEzNTI2MjIyMTYw_size_16_color_FFFFFF_t_70]: /images/20220829/a7e108b171444bcbbb51c212896d9f38.png [https_blog.csdn.net_Owen_goodman_article_details_115521388]: https://blog.csdn.net/Owen_goodman/article/details/115521388 [https_blog.csdn.net_Owen_goodman_article_details_115478298_spm_1001.2014.3001.5501]: https://blog.csdn.net/Owen_goodman/article/details/115478298?spm=1001.2014.3001.5501 [watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16 1]: https://img-blog.csdnimg.cn/82a1880f552e44a6b1d8fb5307164ca5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5biD6KGj5bCP5byg,size_20,color_FFFFFF,t_70,g_se,x_16 [watermark_type_ZHJvaWRzYW5zZmFsbGJhY2s_shadow_50_text_Q1NETiBA5biD6KGj5bCP5byg_size_20_color_FFFFFF_t_70_g_se_x_16 2]: /images/20220829/b52cc5af53d24cf58c0d88fea63e3b8f.png [http_pyarmor.dashingsoft.com_index-zh.html_quick-start]: http://pyarmor.dashingsoft.com/index-zh.html#quick-start [https_blog.csdn.net_u012219045_article_details_114841287]: https://blog.csdn.net/u012219045/article/details/114841287 [https_blog.csdn.net_u012219045_article_details_112259317]: https://blog.csdn.net/u012219045/article/details/112259317 [https_blog.csdn.net_u012219045_article_details_113977724]: https://blog.csdn.net/u012219045/article/details/113977724 [https_blog.csdn.net_sinat_34200786_article_details_79715236]: https://blog.csdn.net/sinat_34200786/article/details/79715236 [https_blog.csdn.net_a645328869_article_details_114059438]: https://blog.csdn.net/a645328869/article/details/114059438 [https_www.shuzhiduo.com_A_GBJrvaWWJ0]: https://www.shuzhiduo.com/A/GBJrvaWWJ0/ [https_blog.csdn.net_Castlehe_article_details_107952649]: https://blog.csdn.net/Castlehe/article/details/107952649 [https_www.bilibili.com_video_BV1bp4y1D7Dg_from_search_seid_14902449668691206456_spm_id_from_333.337.0.0]: https://www.bilibili.com/video/BV1bp4y1D7Dg?from=search&seid=14902449668691206456&spm_id_from=333.337.0.0
还没有评论,来说两句吧...