Python MacOS X上的基本pyinstaller
我正在尝试让Python MacOS X上的基本pyinstaller,python,macos,pyinstaller,Python,Macos,Pyinstaller,我正在尝试让pyinstaller使用我的python脚本,但失败了。所以我尝试了一个非常基本的脚本: #!/usr/bin/env python from matplotlib.pyplot import * from numpy import * x=linspace(0,2*pi,200) plot(x,sin(x)) show() 但这也会失败,错误消息如下。我使用的是最新的山狮,如果有必要的话,我正在使用热情的python。当它位于pyinstaller目录中时,我用python p
pyinstaller
使用我的python脚本,但失败了。所以我尝试了一个非常基本的脚本:
#!/usr/bin/env python
from matplotlib.pyplot import *
from numpy import *
x=linspace(0,2*pi,200)
plot(x,sin(x))
show()
但这也会失败,错误消息如下。我使用的是最新的山狮,如果有必要的话,我正在使用热情的python。当它位于pyinstaller目录中时,我用python pyinstaller.py--onefile../testpyinst.py调用它,完整输出如下:
23 INFO: wrote xxxxxxxxxxxxxx/pyinstaller-2.0/testpyinst/testpyinst.spec
54 INFO: UPX is not available.
1263 INFO: checking Analysis
1337 INFO: checking PYZ
1350 INFO: checking PKG
1350 INFO: building because out00-PKG.toc missing or bad
1350 INFO: building PKG out00-PKG.pkg
Traceback (most recent call last):
File "pyinstaller.py", line 91, in <module>
main()
File "pyinstaller.py", line 86, in main
run_build(opts, spec_file)
File "pyinstaller.py", line 50, in run_build
PyInstaller.build.main(spec_file, **opts.__dict__)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 1625, in main
build(specfile, buildpath)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 1582, in build
execfile(spec)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/testpyinst/testpyinst.spec", line 16, in <module>
console=True )
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 987, in __init__
crypt=self.crypt)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 880, in __init__
self.__postinit__()
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 315, in __postinit__
self.assemble()
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/build.py", line 933, in assemble
archive.build(self.name, mytoc)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/loader/archive.py", line 202, in build
self.save_toc(tocpos)
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/loader/carchive.py", line 250, in save_toc
tocstr = self.toc.tobinary()
File "xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/loader/carchive.py", line 79, in tobinary
nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+pad))
struct.error: argument for 's' must be a string
23信息:编写了xxxxxxxxx/pyinstaller-2.0/testpyinst/testpyinst.spec
54信息:UPX不可用。
1263信息:检查分析
1337信息:正在检查PYZ
1350信息:检查包装
1350信息:由于out00-PKG.toc丢失或损坏而生成
1350信息:建筑包装out00-PKG.PKG
回溯(最近一次呼叫最后一次):
文件“pyinstaller.py”,第91行,在
main()
文件“pyinstaller.py”,主目录第86行
运行构建(选项、规范文件)
文件“pyinstaller.py”,第50行,在run_build中
PyInstaller.build.main(规范文件,**opts.\uuuuu dict\uuuu)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第1625行,主目录
构建(specfile,buildpath)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第1582行,内部版本
执行文件(规范)
文件“xxxxxxxxx/pyinstaller-2.0/testpyinst/testpyinst.spec”,第16行,在
控制台=真)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第987行,在_init中__
crypt=self.crypt)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第880行,在_init中__
self.\uuuu postinit\uuuuu()
文件“xxxxxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第315行,在__
self.assembly()
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/build.py”,第933行,汇编
archive.build(self.name,mytoc)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/loader/archive.py”,第202行,内部版本
自我保存toc(tocpos)
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/loader/carchive.py”,第250行,保存目录
tocstr=self.toc.tobinary()
文件“xxxxxxxxx/pyinstaller-2.0/pyinstaller/loader/carchive.py”,第79行,托比纳里
nmlen+entrylen、dpos、dlen、ulen、flag、typcd、nm+pad)
struct.error:“s”的参数必须是字符串
您是否成功地使用pyinstaller
构建了任何东西?我建议您编写一个没有外部依赖关系的简单代码
print "Hello World!"
或
尝试导入标准库模块,例如math
:
import math
x = 10.0
y = math.sqrt(x)
print "square_root({}) = {}".format(x,y)
接下来,尝试使用只打印sin(x)的numpy
,而不是尝试打印它
from numpy import *
x = linspace(0,2*pi,20)
print sin(x)
如果可行,可以尝试savefig
查看错误是否与试图显示图形有关,而不是show
ing绘图
from matplotlib.pyplot import *
from numpy import *
x=linspace(0,2*pi,200)
plot(x,sin(x))
savefig("/tmp/testfig.png")
如果这仍然不起作用,则matplotlib后端可能存在问题。使用更简单/更标准的方法:
import matplotlib
matplotlib.use("Agg")
from matplotlib.pyplot import *
from numpy import *
x=linspace(0,2*pi,200)
plot(x,sin(x))
savefig("/tmp/testfig.png")
我所做的是打开这个文件
xxxxxxxxxxxxx/pyinstaller-2.0/pyinstaller/loader/carchive.py
,并在第79行之后添加几个print()
。我发现nm+pad不能识别为字符串。但这有点奇怪。我正在使用windows 7,print()
显示nm=kernel32
和pad=''
现在谈谈我的临时解决方案:
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad))
----更改为------>
不确定它是否是一个健壮的解决方案,但它在我的解决方案中有效。我相信你可以用类似的方法来解决你的问题。顺便说一句,我使用的是pyinstaller2.1+python2.7.6。命令是
pyinstaller-F MyApp.py--hidden import=scipy.special.\u ufuncs\u cxx
我的问题与hxu评论中描述的问题相同;改变
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad))
到
对我来说很有用,因为类型(nm)是“unicode”,而类型(pad)str.我在Win7和Pythonxy上也有类似的问题。 我必须编辑文件
C:\Python27\Lib\site packages\pyinstaller-2.1-py2.7.egg\pyinstaller\loader\pyi\u carchive.py
第84-85行,并将nm+pad
更改为str(nm+pad)
原件:
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's',nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad))
修正:
您的代码看起来不错,您可能需要发布更多的回溯,以便人们可以看到错误的开始(该错误不是来自您编写和发布的脚本)。谢谢,我现在添加了完整的输出。不,即使使用最简单的第一个选项
print sin(x)
,它不起作用,并提供与以前相同的回溯。我添加了另一个步骤:查看是否可以导入标准库模块。您的问题可能在于numpy的安装。好的,问题的一部分是选项--onefile
。一旦我删除了它,我就可以让上面的大部分工作正常。对于绘图,我需要添加选项--windowed
,这是应该的,但是对于show()
和matplotlib.use(“WxAgg”)
的交互使用,我确实获得了窗口,但一旦鼠标进入图形窗口,它就会崩溃。错误消息是MKL致命错误:无法加载libmkl_core.dylib
我相信我们现在已经超出了我的专业范围,抱歉,我无法提供更多帮助。现在你已经运行了它,并且有了一个完全不同的bug,也许你有足够的信息在其他地方发布一个更详细的问题(也许是这些人:)@JohnSmith你有没有解决这个问题的方法?我在matplotlib和PyInstaller中遇到了类似的问题,但我一直无法解决。为了澄清这一点:这里更改的代码行解决了当鼠标悬停在图形上时可执行文件崩溃的问题?我能够找到这条线,但不幸的是,更改它对我没有任何影响。隐藏的导入标志是否与此问题相关?决不存在鼠标悬停问题。在上面,我试图解决原始帖子中“s”的结构错误。
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad))
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm.encode('utf8') + pad))
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's',nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad))
rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's',nmlen + entrylen, dpos, dlen, ulen, flag, typcd, str(nm + pad)))