pyinstaller打包带有torch库的python文件转成exe(win10+cuda10.2+Pytorch1.7.0+python3.8)

5 篇文章 0 订阅
5 篇文章 0 订阅

环境配置

RTX1080Ti
Win10
cuda10.2
Pytorch1.7.0
python3.8
pyinstaller4.6

生成exe

命令行输入以下代码

pyinstaller -D your_python.py

接着在python代码所在目录下会生成dist文件夹,里面就有跟你的python文件同名的exe程序和一大堆dll

补充需要的dll

使用pyinstaller本身其实并不难,但是打包带有torch包会有很多dll的问题导致运行exe的时候会有报错。在生成完exe之后还需要做两步操作:
1.将执行目录下带有mkl的一堆dll和一个libopen开头的dll移动到numpy/core目录下
请添加图片描述
到此,再运行程序就能通过了。

Tip:
用pyinstaller打包时,python版本不能使用3.7的,可能会发生以下报错

Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

Current thread 0x00004b5c (most recent call first):

Tip:
打包生成exe后在dist文件夹下的pyd文件和zip文件不要删掉,否则的话可能会导致错误,比如以下错误。

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007ea0 (most recent call first):
<no Python frame>
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值