2

pyinstaller私は失敗した私のpythonスクリプトで作業しようとしています。だから私は非常に基本的なスクリプトを試しました:

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

しかし、これも以下のエラーメッセージで失敗します。私は最新の Mountain Lion を使用しており、問題がある場合は enthought python を使用しています。python pyinstaller.py --onefile ../testpyinst.pypyinstaller ディレクトリにいるときに呼び出します。完全な出力は次のとおりです。

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
4

4 に答える 4

1

私がしたことは、このファイルを開き、79 行目の後xxxxxxxxxxxxxx/pyinstaller-2.0/PyInstaller/loader/carchive.pyにいくつか追加することです。print()そして、nm+pad が文字列として認識されないことがわかりました。それはちょっと奇妙ですが。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

于 2014-11-05T22:50:57.267 に答える
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")
于 2013-02-25T21:25:57.080 に答える
0

Win7 と Pythonxy でも同様の問題がありました。ファイルC:\Python27\Lib\site-packages\pyinstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_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))

修理:

rslt.append(struct.pack(self.ENTRYSTRUCT + repr(nmlen) + 's',nmlen + entrylen, dpos, dlen, ulen, flag, typcd, str(nm + pad)))
于 2015-05-28T21:20:37.303 に答える
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))

type(nm) は「unicode」でしたが、type(pad) str だったので、私にとってはうまくいきました。

于 2014-12-05T09:55:51.257 に答える