Reputation: 65
I have windows 7 64 bit and Python 3.6
I literally dig entire web for solving this - and nothing works sadly.
AttributeError Traceback (most recent call last)
<ipython-input-150-80ee8bd5f0f2> in <module>()
----> serial.Serial()
AttributeError: module 'serial' has no attribute 'Serial'
I tried solve this by: - checking if my file is named serial.py - reinstalling module - at first, entire module didn't work, now only it's functions. - I can't use any of its features, checking ports don't work, nothing works literally. - I checked my pip - everything is fine, module is in folder site-pacages. - If I execute some code inside pySerial files - it works. But there is no serial.Serial or connecting with COM ports (which I try to do.)
Upvotes: 5
Views: 18348
Reputation: 19
If you are on a Windows machine using the Windows Subsystem for Linux (WSL), instead of a virtual machine, you will get this error. To fix it, go into powershell
and enter the command:
wsl --shutdown
Restarting powershell
, and running the pyautogui
script again, worked.
Upvotes: 1
Reputation: 1114
There's another python module called 'serial', that you might have on your system. I was using a program that imports the 'serial' module, and on my Linux machine it worked when executed by one user, and failed when executed as another user.
When running the program as user2, I got the following traceback:
Traceback (most recent call last):
File "./grabserial", line 957, in <module>
restart_requested = grab(sys.argv[1:])
File "./grabserial", line 365, in grab
sd = serial.Serial()
AttributeError: 'module' object has no attribute 'Serial'
I figured out that I had the pyserial 'serial' module in /home/user1/.local/lib/python2.7/site-packages/serial/init.pyc, but that the other user was getting the serial module from /usr/local/lib/python2.7/dist-packages/serial.
There are two different python packages that present a module called 'serial' to the sytem.
One module is called 'serial' by pip (this one is a serialization library), and the other is called 'pyserial' (this one is a serial port handling library).
The simple fix, if what you want to do is use the serial port handling module, is to uninstall the serialization module with pip, and make sure you have the 'pyserial' installed.
In my case, I was using a program that used python 2.7 on my machine, so I did:
$ pip2 uninstall serial
$ pip2 install pyserial
I did this as 'root', so that the pyserial module would be installed globally (for all users). Apparently, user1 had run pip to install pyserial as a local package for their account (so it worked for that account), but in order for other users to to use the module, the module needed to be installed globally. Also, the conflict with the 'serial' module had to be resolved.
Upvotes: 1
Reputation: 71
I had the same problem with Python3 3.6.3.1 installed under Cygwin. I replaced 3.6.3.1 with 3.4.5.1 and the script worked again. OK, but not a good long term solution.
Better solution: I reinstalled Python3 3.6.3.1, and then did "pip install pyserial", and then I was able to run my script. No additional modules show up when I do help("modules"), but something extra must have been added to serial.
Upvotes: 6