基于Python的ERA-5多线程下载——pyinstaller 打包 (2)


基于Python的ERA-5多线程下载分为两部分,《基于Python的ERA-5多线程下载 (1)》,直接再本地使用,即写代码的人使用;《基于Python的ERA-5多线程下载 (2)》使用 pyinsaller 将写好的程序,打包成 .exe 文件,以便其他人使用。

一、正文

1.安装 pyinstaller

开始菜单—Anaconda3 (64-bit)—Anaconda Prompt (Anaconda3),执行以下代码,安装 pyinstaller:

pip install pyinstaller

在这里插入图片描述

2.代码路径修改为相对路径。

将代码中保存的路径,设置为相对路径;程序将在创建子目录,将下载程序下载至此处。

在这里插入图片描述

3.打包 .py 文件。

  1. cd 至 ERA5_Download_Edit.py文件所在目录
  2. 运行 pyinnstall -F ERA5_Download_Edit.py
    在这里插入图片描述

补充:
pyinnstall ERA5_Download_Edit.py,这样也可以打包为 .exe 文件,但是会产生很多依赖包
pyinnstall -F ERA5_Download_Edit.py 将所有的所有依赖程序压缩到.exe文件中,不会产生依赖程序
pyinnstall -F -i ERA5_Download_Edit.py 使用 -i 可以为程序链接图标

4.出现问题,根据提示,修改 .spec 文件

提示:

=============================================================
A RecursionError (maximum recursion depth exceeded) occurred.
For working around please follow these instructions
=============================================================

1. In your program's .spec file add this line near the top::

     import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)

2. Build your program by running PyInstaller with the .spec file as
   argument::

     pyinstaller myprog.spec

3. If this fails, you most probably hit an endless recursion in
   PyInstaller. Please try to track this down has far as possible,
   create a minimal example so we can reproduce and open an issue at
   https://github.com/pyinstaller/pyinstaller/issues following the
   instructions in the issue template. Many thanks.

Explanation: Python's stack-limit is a safety-belt against endless recursion,
eating up memory. PyInstaller imports modules recursively. If the structure
how modules are imported within your program is awkward, this leads to the
nesting being too deep and hitting Python's stack-limit.

With the default recursion limit (1000), the recursion error occurs at about
115 nested imported, with limit 2000 at about 240, with limit 5000 at about
660.

根据提示,修改 .spec 文件。

修改前

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['ERA5_Download_Edit.py'],
             pathex=['E:\\python\\python3_64b\\ERA-5\\ERA5_Download_Edit_Installer'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

修改后

# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(20000)

block_cipher = None


a = Analysis(['ERA5_Download_Edit.py'],
             pathex=['E:\\python\\python3_64b\\ERA-5\\ERA5_Download_Edit_Installer'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

5.继续打包

在命令行(Anaconda Prompt (Anaconda3))中输入 :
此次运行的是 .spec 文件,而不是 .py 文件。

pyinstaller -i E:\python\python3_64b\ERA-5\ERA5_Download_Edit_Installer\myico.ico -F ERA5_Download_Edit.spec

直到运行结束,如图:
在这里插入图片描述

6.运行程序

双击打开:ERA5_Download_Edit.exe,运行程序,创建子目录开始下载。
在这里插入图片描述

二、结语

第一次自己做出来的.exe文件,并且能够正常运行,心里还是蛮高兴的!!!一起加油。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值