2012-01-03 115 views
1

试图学习cx-freeze。我有一个python程序,我试图冻结exe。Python,PySerial和cx-freeze

我使用PySerial,无论我如何尝试包含win32似乎没有任何帮助。我使用Python 3.2和win7。

我已经搜索了网页薄,和其他人有同样的问题,但似乎没有解决方案出现。但我怀疑没有人成功地使用PySerial的cx_freezing。

我完全卡住了。任何帮助,将不胜感激

错误:

Traceback (most recent call last): 
    File "C:\Python32\lib\site-packages\ 
7, in <module> 
    exec(code, m.__dict__) 
    File "snapper.py", line 8, in 
    File "C:\Python32\lib\site-packages\ 
    from serial.serialwin32 import * 
    File "C:\Python32\lib\site-packages\ 
e> 
    from serial import win32 
ImportError: cannot import name win32 

Setup.py:

from cx_Freeze import setup,Executable 

includefiles = ['caml.pkl', 'seql.pkl'] 
includes = ['DataBase', 'serial.win32'] 
excludes = ['Tkinter'] 
packages = [] 

setup(
    name = 'Setup', 
    version = '0.1', 
    description = 'Snapper configuration utility', 
    author = 'LST', 
    author_email = '[email protected]', 
    options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [Executable('snapper.py')] 
) 

任何想法,以何去何从? 在此先感谢

我试图做一个盲目进口:

if False: 
    import serial.win32 

没有运气...

也许我在看这个错误的方式....

+0

如果将include改为'serial'会怎么样? – Velociraptors 2012-01-03 21:57:15

+0

不,试过.. – Esben 2012-01-03 22:12:19

回答

0

如果你可以使用不同的工具来冻结你的程序,PyInstaller表示它支持PySerial。

+2

PyInstaller看起来非常好。但据我所见,不支持python 3.x – Esben 2012-01-03 22:37:13

+0

啊,对不起,我不确定我没有注意到python3标记。 – Velociraptors 2012-01-03 22:40:10

+0

没问题。我是Python的新手,但是我没有看到我是如何从2.7开始的:-)可能很快就会走上这条路...... – Esben 2012-01-03 22:48:15

3

好的,问题解决了。

您需要使用的包强制cx_Freeze包括serial.win32(不是“包括”)

行之后的作品:

packages = ['serial.win32'] 

备忘录对我自己和他人:一定要检查dist文件夹实际包含的软件包。我不知道为什么所有的软件包都没有被cx_Freeze包括在内,但这对我很有用。