"Cannot find reference" error when using pyserial

Disclaimer: I am a beginner at using this forum, and relatively new to coding, so if there is anything I have done incorrectly, please let me know.

Hi. I am trying to use pyserial to get values from my arduino's serial monitor, but whenever I use serial.Serial(), I get an error, which says; "cannot find reference 'Serial' in 'imported module serial'". I think the pyserial module is importing fine, its just that I can't actually code with serial.Serial(). I have attached a few images of the simple code and the error. I am using a python IDE called PyCharm, which is version 2021.1.

I have looked at various forums regarding similar problems to mine, but either none had my problem, or I didn't understand how to fix it. Both of these forums discuss an error which says "module has no attribute Serial", but my error is "cannot find reference 'Serial' in 'imported module serial'". Here are links to some forums I've tried to use:
https://stackoverflow.com/questions/11403932/python-attributeerror-module-object-has-no-attribute-serial

https://raspberrypi.stackexchange.com/questions/74742/python-serial-serial-module-not-found-error

If you have any ideas what my problem may be, or if you need more information about my situation to help me, please let me know.

Edit: I'm also seeing that there is a different error when I try to use serial.Serial() in the terminal, as opposed to pycharm. In pycharm, I get "Cannot find reference 'Serial' in 'imported module serial'", but in the terminal, I get "module 'serial' has no attribute 'Serial'".

Here are images of the code and the error.
Screen Shot 2023-03-13 at 12.20.43 AM

Screen Shot 2023-03-13 at 12.04.17 AM

Thanks in advance.

You probably have the wrong library installed. Perhaps you can try to uninstall the serial library and install pySerial instead. E.g.,

pip uninstall serial
pip install pyserial

Or the equivalent of this in PyCharm.

Hi. Thanks for the answer. Unfortunately, I already have pyserial installed, and didn't have serial installed. I am still getting the same error message.

@tim268 the advice from jfjlaros seems the most likely fix, I would try again and check to make sure I had no 'serial' module installed (type help('modules') to view modules in the REPL) before I installed pyserial. The error message suggests that you have a serial module installed but it appears not to be the right module

Hi. I see that I do not have any module named serial when I type help('modules'), both in pycharm and in the terminal. However, there is also no module named pyserial there. But when I write "import serial", it seems to work fine. I don't understand, is import serial for pyserial? Either way, import serial or import pyserial neither work.

I'm also seeing that there is a different error when I try to use serial.Serial() in the terminal, as opposed to pycharm. In pycharm, I get "Cannot find reference 'Serial' in 'imported module serial'", but in the terminal, I get "module 'serial' has no attribute 'Serial'".

@tim268 the objective is to remove any and all serial modules and then install pyserial, when pyserial is installed it will show as 'serial' in the modules list.

In the terminal if you type dir('serial') the list it produces should include 'Serial' , note the upper case 'S' , if Serial is not present the IDE will complain "Cannot find reference 'Serial' in 'imported module serial'

You are right, there is no 'Serial' there. However, I have uninstalled 'serial', and installed 'pyserial'. Why is this still happening? I have attached pictures of the terminal, when I type dir('serial'), when I try to uninstall serial, and when I try to install pyserial.

Typing dir('serial') into terminal (in python 3):
Screen Shot 2023-03-13 at 2.44.38 PM

Uninstalling serial and installing pyserial messages:
Screen Shot 2023-03-13 at 2.46.31 PM

That gives the contents of the str class ('serial' being a string).
Do dir(serial) instead.

@tim268 sorry I gave you some wrong info in my last post, I will correct that in a second. Looking at your install/uninstall log try the following in your terminal

Leilas-Air:~ cyrus$ pip3 uninstall pyserial
Leilas-Air:~ cyrus$ pip3 install pyserial

what I should have said earlier was at the python prompt type

import serial
dir(serial) #no quotes

What do you see when you type the following?

>>> help('serial')

Here are the first couple of lines I see:

Help on package serial:

NAME
    serial

DESCRIPTION
    # This is a wrapper module for different platform implementations
    #
    # This file is part of pySerial. https://github.com/pyserial/pyserial
    # (C) 2001-2020 Chris Liechti <cliechti@gmx.net>
    #
    # SPDX-License-Identifier:    BSD-3-Clause

Thanks for the advice. I'm now getting 'Serial' showing up and working in python 3 inside the terminal, but I am still getting the Cannot Find Reference error in the pycharme ide. Do you know why this may be?

I'm getting the exact same thing. There was a comment from "sumguy" which seems to have solved the problem in the terminal, but I'm getting the same error in the pycharm IDE. Any ideas what's different when it is there?

You are probably working in a different (virtual) environment there, hence the remark:

I have never used PyCharm myself, but the following page seems relevant.

Thanks a ton for the link. I just had to uninstall and then install the module, and now I'm not getting any error. Thank you so much for all your help.

Good to hear.

Instead of prepending "[solved]" to the subject, you can select the most helpful post as the solution using the "Solution" checkbox. This will lead people with the same question to the correct answer directly.

Ok, thanks for the tip.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.