简体   繁体   中英

Python doesn't find module

I have installed 'pyserial' and 'serial' module after realizing i don't need the 'serial' module which i uninstall. I run on Python 3.8.

After a lot of trials and errors with different code I found on the internet I keep having the same error wich is "AttributeError: module 'serial' has no attribute 'tools'"

Here is my code, which import some package and display the module of the 'serial' library:

import os
import sys
import serial
import pkgutil

package=serial

for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
    print ("Found submodule %s (is a package: %s)" % (modname, ispkg))
print(serial)
print(serial.tools)
os.system("pause")

Here is my output:

C:\Users\ratchet>C:/Users/ratchet/AppData/Local/Programs/Python/Python38-32/python.exe d:/Documents/Code/USBCom.py
Found submodule aio (is a package: False)
Found submodule rfc2217 (is a package: False)
Found submodule rs485 (is a package: False)
Found submodule serialcli (is a package: False)
Found submodule serialjava (is a package: False)
Found submodule serialposix (is a package: False)
Found submodule serialutil (is a package: False)
Found submodule serialwin32 (is a package: False)
Found submodule threaded (is a package: True)
Found submodule tools (is a package: True)
Found submodule urlhandler (is a package: True)
Found submodule win32 (is a package: False)
<module 'serial' (namespace)>
Traceback (most recent call last):
  File "d:/Documents/Code/USBCom.py", line 11, in <module>
    print(serial.tools)
AttributeError: module 'serial' has no attribute 'tools'

So I'm assuming my serial module is imported and the module 'tools' do exist but I still dont understand why it keep telling me this error.

Try inserting the line import serial.tools if you want to print(serial.tools) .

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