将python文件,加密成UE4可用的pyd文件


前言

参考文章:
https://yafeng.blog.csdn.net/article/details/81166062
https://www.cnblogs.com/lvdongjie/p/14181116.html
https://www.cnblogs.com/lazyboy/p/4017567.html

UE4版本:UE4.25.4


一、检查UE4自带的python版本

注:不同版本打包出来的pyd文件,是不能互通导入的

1.通过vs或cdm检查UE4python版本

上一篇文章中有提过:
https://blog.csdn.net/weixin_43912248/article/details/122423597

在这里插入图片描述

二、安装同版本的python

为了不破坏UE4自带的python环境,建议最好还是安装新的python,打包完后一样可以用的

如果会使用trypackage库的,可以是试试(偶尔看到的试库库,还没试验过)

python2.7.14下载链接
https://www.python.org/downloads/release/python-2714/

注意:安装完成后,如果电脑本身有其他版本的python,在cmd使用是要注意区分。

可以将python2.7.14的根目录中的python.exe改名为python27.exe
下文命令将沿用pthon27,根据自己命名修改命令
在这里插入图片描述
如果没有显示,请检查添加配置环境:
https://blog.csdn.net/weixin_43912248/article/details/122423597

三、安装打包pyd所需要的库

1.安装cython

(根据自己的python.exe命名,修改python命令)

python27 -m pip install cython

在这里插入图片描述

2.安装easycython

python27 -m pip install easycython

在这里插入图片描述

四、安装vcpython27

安装教程
https://www.cnblogs.com/lazyboy/p/4017567.html

我这边由于微软的下载链接失效了,随便上个网找来下载的,亲测可用,也上个链接吧
链接:https://pan.baidu.com/s/1CDjOxJOeQ_dsCBjV9lo0pA
提取码:vkgq

以下内容摘自windows平台使用Microsoft Visual C++ Compiler for Python 2.7编译python扩展原文,以防丢失

1.下载完成并安装。以本机为例,安装完成后的路径为:

C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

2.修改python安装目录下Lib\distutils\msvc9compiler.py文件(如有必要可能msvccompiler.py文件也需要做相应更改,视系统而定),找到get_build_version方法直接return 9.0

def get_build_version():
    """Return the version of MSVC that was used to build Python.
 
    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    """
    return 9.0

3.再找到find_vcvarsall方法直接返回vcvarsall.bat的路径(以自己机器安装后的路径为准)

def find_vcvarsall(version):
    """Find the vcvarsall.bat file
 
    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    """
    return r'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat'

五、转pyd操作

1.改文件名

将.py文件重命名为.pyx
在这里插入图片描述

2.cmd命令

在当前文件路径中输入cmd回车,打开当前路径的cmd
在这里插入图片描述

然后在cmd中输入命令

easycython *.pyx

在这里插入图片描述
如果有这个报错,没能生成pyd文件,则按照提示,安装vcpython27
安装教程
https://www.cnblogs.com/lazyboy/p/4017567.html

再重新尝试输入命令即可

六、测试

1.文件夹中的pyd文件是通过init_unreal.py导入执行的

文件夹中只有一个.py文件,让UE4可以执行
在这里插入图片描述

2.打开UE4执行init_unreal.py
在这里插入图片描述

3.执行成功,没有报导入错误
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43912248/article/details/122424873