“模块”对象没有属性“ to_bytes” Python [英] 'module' object has no attribute 'to_bytes' Python

查看:139
本文介绍了“模块”对象没有属性“ to_bytes” Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告知我如何cx冻结使用串行的python程序:

Please advise how I can cx-freeze my python program which uses serial :

    import serial    
    import serial.tools.list_ports;

    print serial.tools.list_ports()

这是我的setup.py

Here's my setup.py

import sys
from cx_Freeze import setup, Executable

    setup(
        name = "My test program",
        version = "3.1",
        description = "My test",
        executables = [Executable("pystest.py", base = "Win32GUI")])

使用cx_freeze构建后,这是我的错误:

After I build using cx_freeze, this is my error :

---------------------------
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "pystest.py", line 1, in <module>
  File "C:\Python27\lib\site-packages\serial\tools\list_ports.py", line 27, in <module>
    from serial.tools.list_ports_windows import *
  File "C:\Python27\lib\site-packages\serial\tools\list_ports_windows.py", line 127, in <module>
    Ports = serial.to_bytes([80, 111, 114, 116, 115]) # "Ports"
AttributeError: 'module' object has no attribute 'to_bytes'

---------------------------
OK   
---------------------------

我不确定为什么会看到这个错误。

I'm not sure why I see this error. Any advise appreciated.

以下是易于阅读的屏幕截图:

Here's a screenshot for easy reading :

谢谢。

推荐答案

import sys
from cx_Freeze import setup, Executable
path = ["pystest"]+sys.path

build_exe_options = {"packages": ["os","serial"], "excludes": ["tkinter"],"path":path}
#add more package what are using for your app?

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "My test program",
        version = "3.1",
        description = "My test",
        options = {"build_exe": build_exe_options},
        executables = [Executable("pystest.py", base=base)])

这篇关于“模块”对象没有属性“ to_bytes” Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆