Python中导入串行错误
我写了
import serial
“出现了消息”。
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/serial/__init__.py", line 20, in ?
from serialposix import *
File "/usr/lib/python2.4/site-packages/serial/serialposix.py", line 13, in ?
import sys, os, fcntl, termios, struct, select, errno
ImportError: No module named termios
怎么了?
I wrote
import serial
There message are occured.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/serial/__init__.py", line 20, in ?
from serialposix import *
File "/usr/lib/python2.4/site-packages/serial/serialposix.py", line 13, in ?
import sys, os, fcntl, termios, struct, select, errno
ImportError: No module named termios
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
termios
至少从 2.0 开始就已经在 Python 标准库中了(我对旧的 Python 版本不是很熟悉),但它一直是一个仅限 Unix 的模块。 如果您在任何 Unix 风格下运行,即除了 Windows 之外的任何版本,或多或少,您的 2.4 应该没问题。 您看到的问题表明Python安装有问题,或者您使用的是非Unix平台(如果不是Windows,我很好奇它是什么)。编辑:OP 已澄清他们使用的是 Debian——Debian 有着从上游组件中删除一些关键部分并将它们隐藏在难以定位的软件包中的悠久历史,这一历史长期以来一直在伤害特别是他们的 Python 包装。
我尝试了几个包搜索引擎,但我找不到它们在哪里隐藏了 Python 的 termios(对于任何版本),所以我能建议的只是解决方法(除非我刚刚添加的 debian 标签吸引了可以提供帮助的 debian 专家)当然,就像在特定于 debian 的论坛上询问一样(当然要明确正在使用的版本)。
也许安装另一个Python(一个真正的Python,而不是“巧妙打包”的Python,即被破坏成碎片并且缺少碎片,Debian 的嘲讽)可能会有所帮助——例如,如果坚持使用Python 2.4 和使用.deb 都是对OP,PYTHON2.4_2.4.6-1UBUNTU3_I386.DEB(当然,不确定它及其依赖项在 OP 的特定 Debian 版本上安装得有多干净); 否则,也可以选择更新且完整的 Python,例如 这里(专门针对 Debian Etch,但希望它可以适应 OP 的确切版本)。
termios
has been in the Python standard library since 2.0 at least (I'm not very familiar with older Python versions), but it's always been a Unix-only module. Your 2.4 should be fine, IF you're running under any Unix flavor -- i.e., anything but Windows, more or less. The problem you're seeing suggests either a faulty Python install, or that you're on a non-Unix platform (and if it's not Windows I'm very curious to learn what it IS).Edit: OP has clarified that they're on Debian -- which has a long history of removing some crucial pieces from upstream components and hiding them in hard-to-locate packages, a history that has long hurt their Python packaging in particular.
I tried several package search engines but I can't find out where they hid termios for Python in particular (for any version) so all I can suggest are workarounds (unless the debian tag I just added attracts debian experts who can help) as well of course as asking on debian-specific forums (clarifying exactly what versions are in use, of course).
Maybe installing another Python (a REAL Python, not the "cleverly packaged", i.e. mangled into pieces and with pieces missing, Debian travesty) might help -- for example, if both sticking with Python 2.4 and using .deb are important constraints to the OP, PYTHON2.4_2.4.6-1UBUNTU3_I386.DEB (not sure how cleanly it and its dependencies install on the OP's specific Debian version, of course); or else, one might as well go with a more recent and complete Python, see for example here (specifically for Debian Etch, but hopefully it can be adapted for the OP's exact version).