[Tutor] Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1)

Steven D'Aprano steve at pearwood.info
Wed Nov 14 16:41:12 EST 2018


On Wed, Nov 14, 2018 at 04:15:57PM +0100, srinivasan wrote:

[...]
> $* pip3 install sh*

You don't need to show every command you ran, if they worked 
successfully.

We're volunteers, giving our own efforts for free, not being paid by the 
hour. The more irrelevant detail you drop in our laps, the fewer of us 
will bother reading it all. Cut out anything not relevant to your actual 
problem. Please read this:

http://sscce.org/

which will help you debug your own problems, and ask better questions 
when you can't debug them yourself.


However, error messages are important: I missed this the first two 
times I read your post, and only spotted it by accident:

> *$ pip3 install bluetoothctl*
> *Collecting bluetoothctl*
> *  Could not find a version that satisfies the requirement bluetoothctl
> (from versions: )*
> *No matching distribution found for bluetoothctl*

You tried to install a package which doesn't exist, or pip cannot find 
it. Since it is not installed, naturally later on you will be unable to 
import that package.


> When I try to paste the below code on pycharm and try to point on the word
> "bluetoothctl" in the beginning of the line "*from sh import bluetoothctl*"
> 
> *from sh import bluetoothctl*
[...]
> In the pycharm, I see the below error message :
> 
> *Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) *
> *Inspection info: This inspection detects names that should resolve but
> don't. Due to dynamic dispatch and duck typing, this is possible in a
> limited but useful number of cases. Top-level and class-level items are
> supported better than instance items.*

That means that PyCharm's linter cannot find any name called 
"bluetoothctl" in the sh.py package. Because PyCharm doesn't know what 
sort of name bluetoothctl is (a subpackage, a module, a class, a 
function, a variable...) it cannot be more specific than saying it can't 
resolve the reference.

In some (rare!) cases, that's not actually a missing name. It just means 
that PyCharm isn't clever enough to determine where the name is, but if 
you actually *run the code* the Python interpreter will find it and the 
code will run correctly.

But this is not the case this time, since you don't actually have 
bluetoothctl installed, so it cannot be imported.

https://duckduckgo.com/?q=bluetoothctl+python




-- 
Steve


More information about the Tutor mailing list