2013-02-25 89 views
2

基本pyinstaller我试图让pyinstaller和我的一个Python脚本无法工作。所以我尝试了一个非常基本的脚本:在MacOS X

#!/usr/bin/env python 
from matplotlib.pyplot import * 
from numpy import * 
x=linspace(0,2*pi,200) 
plot(x,sin(x)) 
show() 

但是,这也失败,下面的错误消息。我在一个跟上时代的山狮和正在使用enthought蟒如果该事项。我在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 
+0

您的代码看起来不错,你可能会需要发布更多的追踪信息,以便人们可以看到错误的开始位置(错误不是来自您写入和发布的脚本)。 – askewchan 2013-02-25 20:54:09

+0

谢谢,我现在添加了完整的输出。 – 2013-02-25 21:13:08

回答

1

你有成功构建任何与pyinstaller?我建议你写一个没有外部依赖一个简单的代码,

print "Hello World!" 

f = open('test.txt','w') 
f.write("Hello World!") 
f.close() 

尝试导入标准库模块,说math

import math 
x = 10.0 
y = math.sqrt(x) 
print "square_root({}) = {}".format(x,y) 

下一页尝试使用numpy只需打印sin(x)而不是试图绘制它。

from numpy import * 
x = linspace(0,2*pi,20) 
print sin(x) 

如果这样的作品,也许代替show荷兰国际集团的阴谋,试图savefig,看看错误有事情做与试图显示这个数字。

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") 
+0

不,即使使用最简单的第一个选项“print sin(x)”,它也不起作用,并提供与之前相同的回溯。 – 2013-02-25 21:36:50

+0

如果您不尝试导入任何内容,该怎么办? (编辑后) – askewchan 2013-02-26 01:08:28

+0

工作。那么如何让进口产品发挥作用呢? – 2013-02-26 04:28:30

1

我所做的就是打开这个文件xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/loader/carchive.py,并且行79后添加几个print()而且我发现纳米+垫不被识别为一个字符串。虽然有点奇怪。我使用Windows 7,print()表明nm=kernel32pad = ''

现在说说我的临时解决方案:

rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad)) 

----改变----->

try: 
    rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, nm + pad)) 
except: 
    ss = str(nm + pad) 
    rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's', nmlen + entrylen, dpos, dlen, ulen, flag, typcd, ss)) 

不知道这是一个强大的解决方案,但它的工作原理矿。我相信你可以使用类似的技术来找出你的。顺便说一句,我正在使用pyinstaller2.1 + python2.7.6。命令是 pyinstaller -F MyApp.py --hidden-import=scipy.special._ufuncs_cxx

+0

澄清:这里更改的代码行解决了当您将鼠标悬停在图上时可执行文件崩溃的问题?我能找到这条线,但不幸的是改变它对我没有任何影响。隐藏导入标志是否与此问题相关? – 2014-11-11 21:25:47

+0

永远不会有鼠标悬停的问题。上面我试图解决在原来的帖子中's'的结构错误。 – hxu 2014-11-14 05:14:45

0

我的问题与hxu的评论中描述的相同;改变

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)) 

为我工作,因为类型(纳米)是 '的unicode',而类型(垫)STR。

0

我与Win7和Pythonxy类似的问题。 我不得不编辑文件C:\Python27\Lib\site-packages\pyinstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_carchive.py线84-85,并改变nm + padstr(nm + 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)))