1

最开始我直接把在Windows上打包的run.exe文件上传到Linux以为可以直接用了。但是./run后报错。百度后知道,Windows上的程序不能在Linux上运行

Linux下文件是否可执行可后缀没有关系,只和权限有关系,靠的是文件本身的权限。想要执行就 chmod 755 filename改变文件权限

windows和linux的二进制文件不能兼容,楼主检查下吧,不能在linux下运行windows的程序.一定要在linux下运行,需要安装wine

Linux默认支持ELF格式二进制文件,Windows的PE格式运行不了的。

2 python用pyinstaller打包后,运行程序报错"pkg_resources.DistributionNotFound"的解决办法

1214984-20171119013850999-296186448.png

最后一句话是重点

pkg_resources.DistributionNotFound:the "APScheduler" distribution was not found....

这里明明已经打包好了exe文件,也没有报错。但是运行exe时候,却弹出这个界面一闪而过。

之后再查阅了pyinstaller的官方文档后,找到了解决办法。

在目标文件目录下创建一个hook-ctypes.macholib.py文件:

里面的内容如下:

# -*- coding: utf-8 -*-

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata('apscheduler')

然后打包的时候,多加一句--additional-hooks-dir=,如下所示:

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

这样修改以后,打包出来的exe文件就能够正常使用了。

3 APScheduler: LookupError: No trigger by the name “interval”was found

环境

python: 2.6.6

PyInstaller: 2.1

APScheduler: 开始是3.0.1,后来是3.0.5

问题一

问题描述

以前在别的机器上开发的python程序(python2.7),在新的机器上运行时报错

LookupError: No trigger by the name "interval" was found

程序代码

importos, timefrom datetime importdatetimefrom apscheduler.schedulers.background importBackgroundSchedulerdefmyjob():print('myjob: %s' %datetime.now())

time.sleep(5)if __name__ == '__main__':

scheduler=BackgroundScheduler()

scheduler.add_job(myjob,'interval', seconds=1)

scheduler.start()try:whileTrue:

time.sleep(5)except(KeyboardInterrupt, SystemExit):

scheduler.shutdown()

原因

是由于低版本的setuptools导致

解决办法

sudo pip install --upgrade setuptools

sudo pip install--ignore-installed apscheduler

然后再次运行上面的python代码,问题解决。

问题二

问题描述

第一个问题解决后,在运行使用pyinstaller打包生成的可执行文件的时候报错

Traceback (most recent call last):

File"", line 11, in File".../out00-PYZ.pyz/apscheduler.schedulers.base", line 330, inadd_job

File".../out00-PYZ.pyz/apscheduler.schedulers.base", line 782, in_create_trigger

File".../out00-PYZ.pyz/apscheduler.schedulers.base", line 766, in_create_plugin_instance

LookupError: No trigger by the name"interval" was found

原因

感觉好像是由于pyinstaller打包的时候使用了错误版本的APScheduler。(不确定)???

解决办法

不要在add_job方法中使用“’interval’, seconds=1”做trigger,而是先创建一个IntervalTrigger对象,然后add_job的时候使用这个对象,即:

修改原来代码中

scheduler.add_job(myjob, 'interval', seconds=1)

trigger = IntervalTrigger(seconds=1)

scheduler.add_job(myjob, trigger)

完整代码如下

defmyjob():print('myjob: %s' %datetime.now())

time.sleep(5)if __name__ == '__main__':

scheduler=BackgroundScheduler()

trigger= IntervalTrigger(seconds=1)

scheduler.add_job(myjob, trigger)

scheduler.start()try:whileTrue:

time.sleep(5)except(KeyboardInterrupt, SystemExit):

scheduler.shutdown()

然后用PyInstaller重新打包,此时再运行可执行文件的时候就不会报错了。

重点:因为用到了IntervalTrigger,所以需要从包里导入,然后我找了这么一个帖子http://blog.csdn.net/mx472756841/article/details/51751616

用了这里面的如下代码

#示例代码

from apscheduler.triggers.interval importIngervalTrigger#使用字符串方式

scheduler.add_job(interval_tick,'interval',seconds=4,minutes=2,

start_date=datetime.now()+dt.timedelta(seconds=120),

end_date=datetime.now()+dt.timedelta(seconds=360))#使用IntervalTrigger指定时间运行

trigger = IntervalTrigger(seconds=60,

start_date=datetime.now()+dt.timedelta(seconds=60),

end_date=datetime.now() + dt.timedelta(seconds=120))

scheduler.add_job(date_tick, trigger)

但是他这里import是错误的。害我找了半天,后来用在在python自带的用户图形界面中import apschedluer 后用dir() 一步一步找到正确的名字,然后才运行通过的。

4 打包成可执行文件后就需要连接本地的数据库(XAMPP上的MySQL)

https://jingyan.baidu.com/article/d169e186467a44436611d8b1.html

可以进入shell后操作(如果host为%号,那么就是所有主机都可以登录,包括远程主机.)

musql -uroot

select host,password,user,from user;

update user set host = "%" where host = "127.0.0.1"

相关文档(http://blog.csdn.net/xiaomengh/article/details/48706149)

5 greenlet.h:8:20: 致命错误: Python.h:没有那个文件或目录

解决方法是安装python-dev,这是Python的头文件和静态库包:

sudo apt-get install python-dev

但还是不行,TODO

TODO

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐