【问题标题】:How to fix "from pexpect_serial import SerialSpawn" error with Python on Windows?如何在 Windows 上使用 Python 修复“from pexpect_serial import SerialSpawn”错误?
【发布时间】:2019-11-04 11:06:20
【问题描述】:

我有一个使用 pexpect、pyserial 模块的旧脚本。在我重新安装 Windows 之前,我运行得非常好。如果不显示以下内容,我现在无法使其运行;

Traceback (most recent call last):
  File "C:\Program Files\Guidance Automation Ltd\kingpiN Programming\KingpinProgramming.py", line 7, in <module>
    from pexpect_serial import SerialSpawn
  File "C:\Program Files\Python37\lib\site-packages\pexpect_serial\__init__.py", line 1, in <module>
    from .serial_spawn import SerialSpawn
  File "C:\Program Files\Python37\lib\site-packages\pexpect_serial\serial_spawn.py", line 24, in <module>
    from pexpect import spawn
ImportError: cannot import name 'spawn' from 'pexpect' (C:\Program Files\Python37\lib\site-packages\pexpect\__init__.py)

我尝试了多种安装 pexpect_serial、pexpect 和 pyserial 模块的组合,以及多个版本的 python,但仍然无济于事。 这似乎是 pexpect-serial 模块的问题。

文件的开头显示为这样;

import sys
import time
import os
import serial
import pexpect.fdpexpect
import pexpect.popen_spawn
from pexpect_serial import SerialSpawn
import paramiko
from config import *

【问题讨论】:

    标签: python windows pyserial pexpect


    【解决方案1】:

    所以,回答我的具体问题...

    我不需要那个模块!我只是将我的代码修改为;

    import sys
    import time
    import os
    import serial
    import pexpect.fdpexpect
    import pexpect.popen_spawn
    #from pexpect_serial import SerialSpawn
    import paramiko
    from config import *
    

    因此它一直运行没有问题!

    所以事后看来,总是先检查模块是否真的需要,然后再沮丧地试图强迫它们工作。

    除此之外,我相信“from pexpect_serial import SerialSpawn”在 Windows 上根本不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-14
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 2023-02-13
      相关资源
      最近更新 更多