本来只是想用Python做一个定时任务小工具在服务器上运行,可是服务器在隔离区,各种禁止上外网,使用pip导出列表那种下载库的方法不管用,导致Python的各种库都下不到,官网离线下载又各种缺依赖,好气啊。后来查了一下,原来还有pyinstaller这种好东西,将需要的库和程序打包成一个可运行的程序,这正是我需要的。  

  为了测试pyinstaller,主要遇到了两个错误,一个是pkg_resources.DistributionNotFound,一个是ImportError: No module named。下面又开始说起,需要看主要解决办法的可以看大标题。

  先搞一个测试小程序吧,这个程序很简单,每5s打印一次a:

#!/usr/bin/env python3
# -*- coding: utf-8 -*- from apscheduler.schedulers.blocking import BlockingScheduler def p():
print("a") if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(p, "cron",second='1/5') try:
scheduler.start()
except Exception as e:
pass

使用pyinstaller打包成一个单独可运行的文件:

pyinstaller -F test1.py

pkg_resources.DistributionNotFound

可是出错了,提示找不到APScheduler,可我已经下载了啊,苦闷。

Traceback (most recent call last):
File "test1.py", line 4, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "c:\users\fstmp\appdata\local\programs\python\python35-32\lib\site-packag
es\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\apscheduler\__init__.py", line 2, in <module>
File "site-packages\pkg_resources\__init__.py", line 535, in get_distribution
File "site-packages\pkg_resources\__init__.py", line 415, in get_provider
File "site-packages\pkg_resources\__init__.py", line 943, in require
File "site-packages\pkg_resources\__init__.py", line 829, in resolve
pkg_resources.DistributionNotFound: The 'APScheduler' distribution was not found
and is required by the application
Failed to execute script test1

我查了一下,官方Issues给出了答案https://github.com/pyinstaller/pyinstaller/issues/1713

大概就是创建一个hook-ctypes.macholib.py,内容是:

#!/usr/bin/env python3
# -*- coding: utf-8 -*- from PyInstaller.utils.hooks import copy_metadata datas = copy_metadata('apscheduler')

然后打包的时候添加--additional-hooks-dir=

pyinstaller -F test1.py --additional-hooks-dir=.

可是,又出现了一个新问题ImportError: No module named

ImportError: No module named

Traceback (most recent call last):
File "site-packages\apscheduler\schedulers\base.py", line 880, in _create_plug
in_instance
KeyError: 'cron' During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "test1.py", line 14, in <module>
File "site-packages\apscheduler\schedulers\base.py", line 411, in add_job
File "site-packages\apscheduler\schedulers\base.py", line 905, in _create_trig
ger
File "site-packages\apscheduler\schedulers\base.py", line 883, in _create_plug
in_instance
File "site-packages\pkg_resources\__init__.py", line 2229, in load
File "site-packages\pkg_resources\__init__.py", line 2235, in resolve
ImportError: No module named 'apscheduler.triggers.cron'
Failed to execute script test1

pkg_resources.DistributionNotFound问题好像解决了,但又来了一个新问题ImportError: No module named

看描述好像是cron哪里出了问题,把CronTrigger单独新建,修正后:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger def p():
print("a") if __name__ == '__main__':
scheduler = BlockingScheduler()
trigger = CronTrigger(second='1/5')
scheduler.add_job(p, trigger) try:
scheduler.start()
except Exception as e:
pass

经过上面修改后,应该可以正常运行了。如果你也有这样的问题,看看我的经验能不能帮到你?

python3使用pyinstaller打包apscheduler出的错的更多相关文章

  1. 【爬坑】python3+pyqt5+pyinstaller 打包成exe的各种问题

    windows系统+python3+pyqt5+pyinstaller打包,经常会出现各种打包异常情况.如果代码没有特别异常,那么综合原因,大抵都是这四个元素之间的匹配问题,引起的.作者:一心狮链接: ...

  2. 【解决】MacOS下 Python3.7 使用 pyinstaller 打包后执行报错 Failed to execute script pyi_rth__tkinter

    Fix tcl/tk libs inclusion in tkinter with Python3.7 under MacOS 使用 Pyinstaller 打包时候报错 3027 ERROR: Tc ...

  3. 【Python】解决使用pyinstaller打包Tkinker程序报错问题

    问题描述 使用pyinstaller打包使用Tkinter编写的控制台程序,出现报错 15793 INFO: Adding Microsoft.Windows.Common-Controls to d ...

  4. moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute fadein、crop

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 在开发moviepy的Python程序使用pyinstaller打包后 ...

  5. python3 使用pyinstaller打包可执行程序

    步骤 1.使用pip安装pyinstaller pip install pyinstaller 2. 使用pyinstaller打包程序 pyinstaller -F xxx.py pyinstall ...

  6. python3.6 pyinstaller 打包exe

    现在的pyinstaller 最新版本已经支持python3.6版本的打包了只需要进行如下的操作即可 1. pip install pyinstaller 2. pip install --upgra ...

  7. 用tkinter写出you-get下载器界面,并用pyinstaller打包成exe文件

    本文为原创文章,转载请标明出处 一.you-get介绍 you-get是一个基于 python 3 的下载工具,使用 you-get 可以很轻松的下载到网络上的视频.图片及音乐.目前支持网易云音乐.A ...

  8. 【Python】pyinstaller打包运行报错failed to execute script main

    前言 最近用pyinstaller打包的时候一直报"failed to execute script main". 最终使用"pyinstaller --hidden-i ...

  9. Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'

    pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...

随机推荐

  1. 关于Linux下转换oracle字符集

    前阵子给以同事导oracle数据库,但是发现导入后数据都是乱码,下面是自己解决这个问题的一些小整理. 比如: #su oralce $export ORACLE_SID=orcl $export OR ...

  2. Java之多态(一)

    package test05; public class DuoTai_Test { /** * 一个对象,多种形态 * WQQ → Student.Worker.Friend 1).一个对象,多种形 ...

  3. mysql can't create threads in threadpool

    最近,我们在券商端的mysql运行一段时间后,发生mysql can't create threads in threadpool,如下所示: 据官网一个报告显示,目测是一个bug,内存紧张导致,那天 ...

  4. javascript的defer和async的区别。

    我们常用的script标签,有两个和性能.js文件下载执行相关的属性:defer和async defer的含义[摘自https://developer.mozilla.org/En/HTML/Elem ...

  5. AndroidStudio安装流程 以及 使用过程中出现的异常

    Android Studio2.0 教程从入门到精通Windows版 - 安装篇 Android Studio第一次启动跳不过“ downloading components”解决方案 通过hosts ...

  6. iOS 杂笔-如何解决tableview显示错乱问题

    解决自定义Tableviewcell显示错乱问题 要是要解决这个问题,就需要用到UITableviewCell的prepareForReuse方法 cell被重用如何提前知道? 重写cell的prep ...

  7. maven 打包含有第三方依赖的 jar 包

    maven 打包含有第三方依赖的 jar 包:mvn assembly:assembly

  8. SSIS 实例——将SQL获取的信息传递到Email中

    最近在为公司财务开发一个邮件通知时遇到了一个技术问题.原来我设计SSIS的是每天将ERP系统支付数据导出到财务支付平台后 Email 通知财务,然后财务到支付平台上进行支付操作.由于那个时候开发时间很 ...

  9. Yii2 vendor出现bower-asset这么解决

    yii\base\InvalidParamException: The file or directory to be published does not exist: /data/wwwroot/ ...

  10. SQL Server 2008 R2——当前日期下,一年前数据的统计值

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...