python3使用pyinstaller打包apscheduler出的错
本来只是想用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出的错的更多相关文章
- 【爬坑】python3+pyqt5+pyinstaller 打包成exe的各种问题
windows系统+python3+pyqt5+pyinstaller打包,经常会出现各种打包异常情况.如果代码没有特别异常,那么综合原因,大抵都是这四个元素之间的匹配问题,引起的.作者:一心狮链接: ...
- 【解决】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 ...
- 【Python】解决使用pyinstaller打包Tkinker程序报错问题
问题描述 使用pyinstaller打包使用Tkinter编写的控制台程序,出现报错 15793 INFO: Adding Microsoft.Windows.Common-Controls to d ...
- moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute fadein、crop
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 在开发moviepy的Python程序使用pyinstaller打包后 ...
- python3 使用pyinstaller打包可执行程序
步骤 1.使用pip安装pyinstaller pip install pyinstaller 2. 使用pyinstaller打包程序 pyinstaller -F xxx.py pyinstall ...
- python3.6 pyinstaller 打包exe
现在的pyinstaller 最新版本已经支持python3.6版本的打包了只需要进行如下的操作即可 1. pip install pyinstaller 2. pip install --upgra ...
- 用tkinter写出you-get下载器界面,并用pyinstaller打包成exe文件
本文为原创文章,转载请标明出处 一.you-get介绍 you-get是一个基于 python 3 的下载工具,使用 you-get 可以很轻松的下载到网络上的视频.图片及音乐.目前支持网易云音乐.A ...
- 【Python】pyinstaller打包运行报错failed to execute script main
前言 最近用pyinstaller打包的时候一直报"failed to execute script main". 最终使用"pyinstaller --hidden-i ...
- Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'
pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...
随机推荐
- php实现设计模式之 状态模式
<?php /*状态模式:允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它的类.(行为模式) * * 在很多情况下,一个对象的行为取决于一个或多个动态变化的属性,这样的属性叫做 ...
- Maven远程仓库的配置
在很多情况下,默认的中央仓库无法满足项目的需求,可能项目需要的构件存在于另外一个远程仓库中,如JBoss Maven仓库.这时,可以在POM中配置该仓库,见代码如下: <!-- 远程仓库的配置 ...
- opts=opts | |{}
var opts=opts || {}这个语句是一个赋值或者初始化语句 该语句在opts已经被初始化过后opts的值不变,即执行var opts=opts这一部分. 当opts未被初始化,即typeo ...
- ListView和Adapter数据适配器的简单介绍
ListView 显示大量相同格式数据 常用属性: listSelector listView每项在选中.按下等不同状态时的Drawable divider ...
- [Android]使用Dagger 2依赖注入 - DI介绍(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5092083.html 使用Dagger 2依赖注入 - DI介 ...
- android环境下的即时通讯
首先了解一下即时通信的概念.通过消息通道 传输消息对象,一个账号发往另外一账号,只要账号在线,可以即时获取到消息,这就是最简单的即使通讯.消息通道可由TCP/IP UDP实现.通俗讲就是把一个人要发送 ...
- Android 从零开始打造异步处理框架
转载请标明出处:http://www.cnblogs.com/zhaoyanjun/p/5995752.html 本文出自[赵彦军的博客] 概述 在Android中会使用异步任务来处理耗时操作,避免出 ...
- android6.0的坑
虽然现在android已经出了7.0了.但是大部分人用的应该还是5.0和6.0的. 其中对于开发者来说,变化比较大的应该是6.0之前和6.0之后的版本. 因为以6.0为分界线多了一个比较坑的东西:权限 ...
- android:使用Messenger进行进程间通信(一)
Messenger简介 Messenger和AIDL是实现进程间通信(interprocess communication)的两种方式. 实际上,Messenger的实现其实是对AIDL的封装. Me ...
- linux shell程序
shell程序介绍 1.查看我们的Linux(centos6.5为例)有多少我们可以使用的shell: [root@localhost bin]# cat /etc/shells /bin/sh /b ...