[英]Python3 won't find a module even though it is properly installed
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
. 我正在使用Python 3.6.7 venv,并且安装了
PyBluez
蓝牙库,以及其所有依赖项,例如sudo apt install bluetooth libbluetooth-dev python3-bluez
。 When I run my python script, I'm getting: 当我运行python脚本时,我得到:
`ModuleNotFoundError: No module named 'bluetooth' `ModuleNotFoundError:没有名为'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. 疯狂的部分是,我刚刚检查了环境的
/lib/python3.6/site-packages/
目录, 确实存在名为bluetooth和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. 甚至仍然,当我进入
bluetooth
目录时, 确实存在一个ble.py
文件,一个_bluetooth.cpython.so
文件(名称缩写) 和一个bluez.py,它们中均包含有效代码。 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. 所有依赖项都是通过在虚拟环境中通过
pip3 install
,甚至已通过python3 -m pip install
进行了验证,python3声称已将其python3 -m pip install
到该库中。 Additionally, ls -la
shows drwxrwxr-x just like every other dependency in the site-packages
folder. 另外,
ls -la
显示drwxrwxr-x就像site-packages
文件夹中的所有其他依赖项一样。 What is the problem here? 这里有什么问题?
Note: I've also verified install with pip3 list
from inside the venv. 注意:我还通过
pip3 list
验证了pip3 list
安装。
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]
. 注意2:Visual Studio Code似乎无法找到模块...用红色下划线标记,并且pylint扩展名表明
unable to import [modulename]
。 This is only true for modules installed in the venv. 这仅适用于安装在venv中的模块。 This may just be an error with pylint extension searching the system libs rather than my vent's libs... Not a big deal.
这是pylint扩展搜索系统库而不是我的通风口的库时出现的错误。
As you installed python3-bluez
as apt package, this is installed in the global site packages of your system. 在将
python3-bluez
作为apt软件包安装时,它已安装在系统的全局站点软件包中。 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. 默认情况下,virtualenv不会从全局站点程序包中继承程序包,因此在virtualenv环境中,您实际上无法从全局站点程序包中导入任何模块。 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. 但是,可以在创建带有
--system-site-packages
标志的virtualenv环境时,或者从lib/pythonX.X/
目录中删除no-global-site-packages.txt
创建后,从全局站点包继承。 For more information please follow the official documentation . 有关更多信息,请遵循官方文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.