I created a "python block" using gnuradio on WINDOWs, got
module serial' has no attribute Serial
error in it, but put
'SerialIn = serial.Serial("COM16",0)'
After commenting it out, there is no error, which proves that it is not a problem of
import serial
There is a method to reinstall it on the Internet, but it still doesn't work, how can I fix it?
I am trying to detect objects in a picture. I am using my trained weights and configuration file. The code runs completely fine on my laptop but it shows
AttributeError: module 'cv2' has no attribute 'dnn'
when I run it on my Raspberry Pi 4B. I have python 3.7 and Open CV 4.5.1
I am unable to solve this.
what should I do.
I'm aware of this being the same question as in this thread. However, I tried the named solutions (yes, all of them [I think]) and it still gives the same error message.
I tried to establish a serial connection between my Raspberry and Arduino (Mega 2560). After installing the serial package (pip install serial, sudo apt-get install python-serial), my script file being called "arduino.py", the code being:
import serial
MySer = serial.Serial('/dev/ttyUSB0', 9600)
I still get the same error message (AttributeError: 'module' object has no attribute 'Serial').
Now did I do something inherently wrong? Do I have to set some permissions or... I'm a little lost here. ^^
Thanks in advance,
Tim
Thanks dda - that was the right direction.
I uninstalled serial and installed pyserial, now it works phenomenally (at least from what I gather in the few minutes between coffee and work).
Thank you so much!
Best of wishes,
Tim
I get a nameError when using Serial. I believe that i am not importing serial properly.
from serial import *
serialPort = Serial("COM3", 9600)
i've installed pyserial through pip. Am i doing something wrong? Has anyone else experienced this error?
You called your file serial.py, which will shadow the installed serial module.
Rename your file to something else, then it should work.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 4 years ago.
I'm trying to access a serial port with Python 2.6 on my Raspberry Pi running Debian.
My script named serial.py tries to import pySerial:
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write("hello world!")
For some reason it refuses to establish the serial connection with this error:
AttributeError: 'module' object has no attribute 'Serial'
When I try to type the same code in the interactive Python interpreter it still doesn't work.
Strangely, it used to work about a couple hours ago.
What could be the problem? I've tried to fix this for a while, installing pySerial again, rewriting my code, double-checking the serial port, etc.
I'm adding this solution for people who make the same mistake as I did.
In most cases: rename your project file 'serial.py' and delete serial.pyc if exists, then you can do simple 'import serial' without attribute error.
Problem occurs when you import 'something' when your python file name is 'something.py'.
I accidentally installed 'serial' (sudo python -m pip install serial) instead of 'pySerial' (sudo python -m pip install pyserial), which lead to the same error.
If the previously mentioned solutions did not work for you, double check if you installed the correct library.
You're importing the module, not the class. So, you must write:
from serial import Serial
You need to install serial module correctly: pip install pyserial.
You have installed the incorrect package named 'serial'.
Run pip uninstall serial for python 2.x or pip3 uninstall serial
for python 3.x
Then install pyserial if not already installed by
running pip install pyserial for python 2.x orpip3 install pyserial for python 3.x.
If you are helpless like me, try this:
List all Sub-Modules of "Serial" (or whatever package you are having trouble with) with the method described here: List all the modules that are part of a python package
In my case, the problems solved one after the other.
...looks like a bug to me...
This error can also happen if you have circular dependencies. Check your imports and make sure you do not have any cycles.
Yes this topic is a bit old but i wanted to share the solution that worked for me for those who might need it anyway
As Ali said, try to locate your program using the following from terminal :
sudo python3
import serial
print(serial.__file__) --> Copy
CTRL+D #(to get out of python)
sudo python3-->paste/__init__.py
Activating __init__.py will say to your program "ok i'm going to use Serial from python3". My problem was that my python3 program was using Serial from python 2.7
Other solution: remove other python versions
Cao
Sources :
https://raspberrypi.stackexchange.com/questions/74742/python-serial-serial-module-not-found-error/85930#85930
Tryhard