1

上周我一直在努力使用 pyinstaller/py2exe 将一些 python 脚本和 pyqt .ui 文件编译成 exe。我对编程相当陌生,以前从未尝试过打包应用程序以进行分发。

到目前为止,我已经成功地将我的 gui 应用程序简化为一个 python 脚本,但是当我尝试使用 py2exe 或 pyinstall 编译它时,我得到了同样的错误。

使用 pyinstaller 的错误是:

C:\Python27\pyinstaller-2.0>python utils\build.py costaharmplotter.spec
109 INFO: Testing for ability to set icons, version resources...
187 INFO: ... resource update available
203 INFO: UPX is not available.
2515 WARNING: library python%s%s required via ctypes not found
2625 INFO: checking Analysis
2625 INFO: building Analysis because out00-Analysis.toc non existent
2625 INFO: running Analysis out00-Analysis.toc
2625 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable

2640 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21
022.8_x-ww ...
2640 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC90.CRT_1fc
8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375.manifest
2656 INFO: Searching for file msvcr90.dll
2656 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_
9.0.21022.8_x-ww_d08d0375\msvcr90.dll
2656 INFO: Searching for file msvcp90.dll
2656 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_
9.0.21022.8_x-ww_d08d0375\msvcp90.dll
2656 INFO: Searching for file msvcm90.dll
2656 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_
9.0.21022.8_x-ww_d08d0375\msvcm90.dll
2812 INFO: Analyzing C:\Python27\pyinstaller-2.0\support\_pyi_bootstrap.py
5484 WARNING: library python%s%s required via ctypes not found
5562 INFO: Analyzing C:\Python27\pyinstaller-2.0\PyInstaller\loader\archive.py
5875 INFO: Analyzing C:\Python27\pyinstaller-2.0\PyInstaller\loader\carchive.py
6297 WARNING: pywintypes is changing its name to pywintypes27
6797 INFO: Analyzing C:\Python27\pyinstaller-2.0\PyInstaller\loader\iu.py
6843 INFO: Analyzing costaharmplotter.py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1844, in Tcl
    return Tk(screenName, baseName, className, useTk)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1745, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, want
objects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
    {C:\Tcl\lib\tcl8.5} C:/Python27/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/li
brary C:/library C:/tcl8.5.2/library C:/tcl8.5.2/library

C:/Tcl/lib/tcl8.5/init.tcl: version conflict for package "Tcl": have 8.5.2, need
 exactly 8.5.13
version conflict for package "Tcl": have 8.5.2, need exactly 8.5.13
    while executing
"package require -exact Tcl 8.5.13"
    (file "C:/Tcl/lib/tcl8.5/init.tcl" line 18)
    invoked from within
"source C:/Tcl/lib/tcl8.5/init.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list source $tclfile]"


This probably means that Tcl wasn't installed properly.

我在 py2exe 中遇到了类似的错误:

C:\Documents and Settings\T53983\Desktop\HarmonicPlotterGUI>python setup.py py2e
xe
running py2exe
*** searching for required modules ***
*** parsing results ***
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(data_files=['C:\\Python27\\tcl\\tcl8.5\\init.tcl'], console = ['costah
armplotter.py'])
  File "C:\Python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 299, in _run
    py_files, extensions, builtins = self.parse_mf_results(mf)
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1097, in parse_
mf_results
    tk = _tkinter.create()
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
    {C:\Tcl\lib\tcl8.5} C:/Python27/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/li
brary C:/library C:/tcl8.5.2/library C:/tcl8.5.2/library

C:/Tcl/lib/tcl8.5/init.tcl: version conflict for package "Tcl": have 8.5.2, need
 exactly 8.5.13
version conflict for package "Tcl": have 8.5.2, need exactly 8.5.13
    while executing
"package require -exact Tcl 8.5.13"
    (file "C:/Tcl/lib/tcl8.5/init.tcl" line 18)
    invoked from within
"source C:/Tcl/lib/tcl8.5/init.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list source $tclfile]"


This probably means that Tcl wasn't installed properly.

在我的脚本中,我使用了 numpy、pyqtgraph.PlotWidget、pyqt4.QtCore 和 pyqt4.qtgui。

  • 如果我不使用 tkinter,为什么 py2exe/pyinstaller 会寻找 tcl?
  • 我该如何排除导致问题的这个包?我已经将 tcl 文件从 tcl 8.5.13 切换到 tcl 8.5.2 但它仍然无法正常工作。

请不要将我链接到 py2exe/pyinstaller 文档,过去几天我一直在阅读它,但仍在努力理解所有选项的工作原理。我将在下面发布我的 setup.py 文件和规范文件以供参考。

setup.py 文件:

from distutils.core import setup
import py2exe

setup(console = ['costaharmplotter.py'])

规格文件:

# -*- mode: python -*-
a = Analysis(['costaharmplotter.py'],
             pathex=['C:\\Python27'],
             hiddenimports=[],
             hookspath=None)
pyz = PYZ(a.pure - [('Tkinter','C:\\Python27\\lib\\lib-tk','PYMODULE')])
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=1,
          name=os.path.join('build\\pyi.win32\\costaharmplotter', 'costaharmplotter.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name=os.path.join('dist', 'costaharmplotter'))
4

1 回答 1

0

上次我尝试 py2exe 时,我无法让它与比 Python 2.6 更新的任何东西一起工作。查看Sourceforge和旧的更新/新闻页面,似乎仍然不支持比 2.6/2.7 更新的任何内容。

看起来您使用的是 2.7,因此请尝试使用 Python 2.6 进行编译。

于 2013-07-19T17:48:27.113 回答