Now I am trying to change a program from Java into Python, when I finally fix three problems on my code and I run it. Then shows me this Error.
Traceback (most recent call last):
File "serial.py", line 4, in <module>
import serial
File "/home/pi/serial.py", line , in <module>
port=serial.Serial(
AttributeError:'module' object has no attribute 'Serial'
How can I fix it?
If you need the source code and What were the problems that I had to fix, let me know. Please help me about it.
Your problem is simple - you have given your script file the same name as the library you are importing.
Fix: rename your file to some other name, e.g. serial.py -> serial_test.py and this should fix the problem.
I think import serial is wrong.
Did you try:-
from serial import serial
http://pyserial.sourceforge.net/shortintro.html
You've most likely named your file serial.py or maybe Serial.py. Rename your file to something else, "TestSerial.py" if you're desperate to keep that name.
Golden Rule of Python: Never give a file the same name as a module you are importing from
Now I am trying to change a program from Java into Python, when I finally fix three problems on my code and I run it. Then shows me this Error.
Traceback (most recent call last):
File "serial.py", line 4, in <module>
import serial
File "/home/pi/serial.py", line , in <module>
port=serial.Serial(
AttributeError:'module' object has no attribute 'Serial'
How can I fix it?
If you need the source code and What were the problems that I had to fix, let me know. Please help me about it.
Your problem is simple - you have given your script file the same name as the library you are importing.
Fix: rename your file to some other name, e.g. serial.py -> serial_test.py and this should fix the problem.
I think import serial is wrong.
Did you try:-
from serial import serial
http://pyserial.sourceforge.net/shortintro.html
You've most likely named your file serial.py or maybe Serial.py. Rename your file to something else, "TestSerial.py" if you're desperate to keep that name.
Golden Rule of Python: Never give a file the same name as a module you are importing from
0 commentaires:
Enregistrer un commentaire