python - "ImportError: No module named serial"- 安装 pyserial 之后

标签 python windows

我正在用 Python 编写一个项目,最终应该会在 LinkIt One IoT 设备上运行。

我已经编写了一些测试代码来检查我是否能够将 Arduino IDE 连接到 python(我正在使用 Pycharm)。

测试代码为:

import serial
import time

arduino = serial.Serial('COM1', 115200, timeout=.1)

time.sleep(1) #give the connection a second to settle

arduino.write("Hello from Python!")

while True:
    data = arduino.readline()
    if data:
        print data.rstrip('\n')

当我运行代码时,我得到:

C:\Users\אורי\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/אורי/PycharmProjects/untitled2/test.py

Traceback (most recent call last): File "C:/Users/����/PycharmProjects/untitled2/test.py", line 1, in import serial ImportError: No module named serial

最佳答案

你是如何安装串口模块的? 如果你想确保它会被检测到, 进入你的控制台

pip install serial

并从控制台运行你的代码

python test.py # make sure your console is in the right folder path

找到模块的安装位置,比如“C:\Python27\Lib\site-packages”

import sys
sys.path.append("C:\Python27\Lib\site-packages") # this is where python stores modules, yours could be different 
import serial

关于python - "ImportError: No module named serial"- 安装 pyserial 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49916535/

相关文章:

c++ - 性能计数器索引 windows pdh c

windows - 在Windows上启动Docker构建时的问题

python - Sublime Text 2 - 无法运行带有空格和引号的 Windows 命令

windows - node.js 无法识别 express

python - ML - 特征选择后获取特征名称 - SelectPercentile,python

javascript - 从 python 列表创建 html 中动态数量的 slider 并使用 javascript 显示值?

windows - 如何在 msysgit/Cygwin 脚本中测试管理员权限?

.net - 通过多台机器对数据进行时间戳记 - 时间不对?

python - 根据另一个数据框检查数据框中的值并附加值(如果存在)

python - 将 a[i+j] 数组映射到 A[i,j] 矩阵