简体   繁体   中英

Python serial module works in command line but not from script

For reference I have used pyserial for dozens of hours succesfully

When I

>>> import serial
>>> ser = serial.Serial()
>>> ser.baudrate = 115200
>>> ser.port = "/dev/ttyACM0"
>>> ser.open()

it works exactly as expected. however, when i call the exact same sequence in a python3 script and run it I get a "AttributeError: module 'serial' as no attribute 'Serial'.

When I run dir() on both serial modules I get the expected result from my command line serial, but I only get like 5 functions listed when I do print the results of dir(serial) in my script. After running my script which fails, the command line serial version no longer works either. I have to pip uninstall and reinstall it for it to work again.

For reference I am on Ubuntu 18.04

bad mistake! I had named the python script I was trying to run was called serial.py!!

that was conflicting with importing the serial library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM