小编Rya*_*nan的帖子

py2app构建正常,但应用程序失败"_tkinter.TclError"(并且没有错误消息!)

我使用py2app 0.9Mac OSX Yosemite 10.10.1运行Python 3.4,从蟒蛇分布,并用Tcl 8.5.

在早期的尝试中,构建会失败,但快速搜索会显示这些问题的解决方案(即包括'packages':['tkinter', 'matplotlib']在OPTIONS中setup.py,并更改第49行MachOGraph.py:loader - > loader_path)

现在py2app完成构建,并在Alias模式下运行我的应用程序功能,但是当我在普通模式(python setup.py py2app)中构建时,生成的应用程序将无法打开,并且控制台显示以下回溯:

回溯(最近一次调用最后一次):文件"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/ boot .py",第355行,在_run()文件"/ Users/ryankeenan /桌面/钓鱼/ gui_test/dist/deani.app/Contents/Resources/boot .py",第336行,在_run exec(编译(源,路径,'exec'),globals(),globals())文件"/用户/ ryankeenan /桌面/钓鱼/ gui_test/dist/deani.app/Contents/Resources/deani.py",第731行,在app = fishingapp()文件"/ Users/ryankeenan/Desktop/fishing/gui_test/dist/deani .app/Contents/Resources/deani.py",第536行,在init tk.Tk中.init(self,*args,**kwargs)文件"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/lib/python3..py",第1851行,在init self.tk = _tkinter.create(screenName,baseName,className,interactive,wantobjects,useTk,sync,use)_tkinter.TclError

令人沮丧的是,它不会为"_tkinter.TclError"打印任何错误消息.我搜索了很多,没有找到任何解决方案或这个问题的复制品.我已经尝试构建各种基于tkinter的应用程序,它们都以同样的方式失败.

这是在第一次拨打tk.Tk时发生的.我的代码中的init(self,*args,**kwargs).

我的setup.py文件如下所示:

from setuptools import setup 
APP = ['deani.py'] 
DATA_FILES = [] 
OPTIONS = {'packages': ['tkinter','matplotlib'],'argv_emulation': True} 
setup( 
     app=APP, 
     data_files=DATA_FILES, …
Run Code Online (Sandbox Code Playgroud)

tkinter py2app python-3.x anaconda

13
推荐指数
1
解决办法
613
查看次数

如何将Python numpy数组转换为base64输出

基本上,我需要做这个,但是在Python而非JavaScript.我从socketio连接接收到base64编码的字符串,将其转换为uint8并对其进行处理,然后需要将其转换为base64字符串,以便我可以将其发回.

所以,到目前为止,我已经得到了这个(我data从socketio服务器获取字典):

import pickle
import base64
from io import BytesIO
from PIL import Image

base64_image_string = data["image"]
image = Image.open(BytesIO(base64.b64decode(base64_image_string)))
img = np.array(image)
Run Code Online (Sandbox Code Playgroud)

我如何扭转这个过程从img回到base64_image_string

更新:
我已通过以下方式解决了这个问题(从上面的代码片段继续):

pil_img = Image.fromarray(img)
buff = BytesIO()
pil_img.save(buff, format="JPEG")
new_image_string = base64.b64encode(buff.getvalue()).decode("utf-8")
Run Code Online (Sandbox Code Playgroud)

有点令人困惑,new_image_string不一样,base64_image_string但是new_image_string看起来相同的图像,所以我很满意!

python arrays base64

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

anaconda ×1

arrays ×1

base64 ×1

py2app ×1

python ×1

python-3.x ×1

tkinter ×1