0

I'm using a Python 3.6.7 venv and I have installed the PyBluez bluetooth library, in addition to ALL of its dependencies such as sudo apt install bluetooth libbluetooth-dev python3-bluez . When I run my python script, I'm getting:

`ModuleNotFoundError: No module named 'bluetooth'

The crazy part is that I've just checked my environment's /lib/python3.6/site-packages/ directory and there is indeed directories entitled bluetooth and a PyBluez-0.22,egg-info.

even still, when I go into the bluetooth directory, there is indeed a ble.py file, a _bluetooth.cpython.so file (name abbreviated), and a bluez.py, all with valid code in them. All dependencies were installed via pip3 install from within the virtual environment and even verified with python3 -m pip install to which python3 claimed they were already installed. Additionally, ls -la shows drwxrwxr-x just like every other dependency in the site-packages folder. What is the problem here?

Note: I've also verified install with pip3 list from inside the venv.

Note2: Visual Studio Code seems to not be able to locate the modules... They are underlined in red and pylint extension says unable to import [modulename]. This is only true for modules installed in the venv. This may just be an error with pylint extension searching the system libs rather than my vent's libs... Not a big deal.

the_endian
  • 2,259
  • 1
  • 24
  • 49

1 Answers1

0

As you installed python3-bluez as apt package, this is installed in the global site packages of your system. By default, virtualenv doesn't inherit packages from global site packages, so inside a virtualenv environment you can't actually import any module from global site packages. But this can be enabled to inherit from global site package on creation of virtualenv environment with --system-site-packages flag or after creation by removing no-global-site-packages.txt from lib/pythonX.X/ directory. For more information please follow the official documentation.

arryph
  • 2,725
  • 10
  • 15