Python ImportError:无法在Twisted上导入名称SerialPort
我在使用一个简单的twisted程序时遇到问题,运行时出现以下错误:Python ImportError:无法在Twisted上导入名称SerialPort,python,import,twisted,pyserial,Python,Import,Twisted,Pyserial,我在使用一个简单的twisted程序时遇到问题,运行时出现以下错误: Traceback (most recent call last): File "serial.py", line 1, in <module> from twisted.internet.serialport import SerialPort File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/pyth
Traceback (most recent call last):
File "serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/serialport.py", line 22, in <module>
import serial
File "/Users/me/Desktop/serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
ImportError: cannot import name SerialPort
我运行的是Twisted 13.2.0、Python2.7,这两个版本都经过了更新,还安装了PySerial 2.7。因此,我相信一切都已安装并更新。此错误发生在两个不同的系统上
以下各项运行正常:
python -c "from twisted.internet.serialport import SerialPort"
谢谢你的帮助。这与PySerial有冲突吗?请看这些回溯行:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/serialport.py", line 22, in <module>
import serial
File "/Users/me/Desktop/serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
这是来自Twisted的一条线。根据这一事实,您可以猜测代码要导入的串行
模块不是您编写的
然后查看回溯中的下一个文件:/Users/me/Desktop/serial.py
。这说明Python在您的个人桌面目录中找到了串行
模块<代码>导入序列现在正在运行您编写的代码。根据之前的推测,这可能是一件坏事
清除
serial.py
(和serial.pyc
和serial.pyo
如果存在),然后重试。它可能仍然不起作用,但问题的原因(因此回溯)至少应该是不同的。不要给脚本命名serial.py
。这是个好主意,但没有帮助。它可能有帮助。删除Python在serial.py旁边自动写出并正在导入的serial.pyc。然后确保你已经安装了pyserial,这就是诀窍。我想知道为什么会出现serial.pyc文件。谢谢你,还有胡博。
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/serialport.py", line 22, in <module>
import serial
File "/Users/me/Desktop/serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
import serial