使用 sudo (Raspberry Pi) 运行代码时没有名为 pandas 的模块
我正在尝试检测 Raspberry Pi 4 上的击键。为此,我运行代码,
sudo python3 example.py
但出现错误“没有名为 Pandas 的模块”(代码使用 Pandas)。但是当我使用 Thonny 运行代码时,我没有收到任何错误。我还安装了 pandas(使用“pip list”确认)。所以,显然如果我以 root 身份运行代码,我会得到“没有名为 pandas 的模块”。如果我运行代码,
python3 example.py
那么 pandas 没有问题,但 python 键盘模块会因为需要 root 访问而引发错误。我检查过,
which python
>>>/usr/bin/python
sudo which python
>>>/usr/bin/python
然后我进行了比较,
pip3 list
sudo pip3 list
令人惊讶的是我发现 pip3 list 给了我 pandas(1.4.1)。但是 sudo pip3 列表中没有找到 pandas!现在我所做的是,
sudo pip3 install pandas
现在错误已更改为“numpy.ndarray 大小已更改,可能表明二进制不兼容。预期来自 C 标头的 48,从 PyObject 获得 40”。但仅在以 sudo 身份运行代码时才会发生。
I am trying to detect keystroke on my Raspberry Pi 4. To do that I am running the code as,
sudo python3 example.py
But I get error, "No module named Pandas" (The code uses Pandas). But When I am running the code using Thonny, I get no error. And also I have pandas installed (confirmed using "pip list"). So, apparently If I run the code as root I get "no modules named pandas". If I run the code as,
python3 example.py
then no problem with pandas, but python keyboard module throws an error because of root access required. I have checked,
which python
>>>/usr/bin/python
sudo which python
>>>/usr/bin/python
Then I compared between
pip3 list
sudo pip3 list
Surprisingly I found that pip3 list gives me pandas(1.4.1). But no pandas were found in sudo pip3 list!!! Now what i did was,
sudo pip3 install pandas
Now the error has changed to, "numpy.ndarray size changed, may indicate binary incompatibility. Expected 48 from C header, got 40 from PyObject". But occurring only when running code as sudo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的直觉告诉我,为超级用户安装的软件包可能与为基本用户安装的软件包不同——如果 pandas 是通过 pip3 install --user pandas 安装的,则可能会发生这种情况。或者,用户和 sudo 可能使用不同版本的 python。
要开始调试,我将比较
sudo which python
和which python
以及sudo pip3 list
的输出,并查找以下方面的任何差异环境。My intuition tells me that the packages installed for the superuser might be different than the packages installed for the base user -- this could happen if pandas was installed via
pip3 install --user pandas
. Alternatively, the user and sudo might be using different versions of python.To start debugging, I'd compare the output of
sudo which python
andwhich python
as well assudo pip3 list
and look for any differences in environment.