尝试导入 plotly.express 但即使安装了 pandas 也会出现此错误:ImportError: Plotly express requires pandas to be installed

问题描述 投票:0回答:2

我有一个带有 Python 3.7.3 的 Raspberry Pi 盒子,我正在尝试创建一个饼图,但在这种情况下,我在 very 第一步失败了。但每次我跌倒,我都在学习负载。

我的脚本包含以下导入:

将 plotly.express 导入为 px

我在尝试运行 .py 脚本时得到了这个

import plotly.express as px
File "/home/pi/.local/lib/python3.7/site-packages/plotly/express/__init__.py", line 12, in <module>
Plotly express requires pandas to be installed."""
ImportError: Plotly express requires pandas to be installed.

但是我安装了 pandas,如果我运行:

点子秀熊猫

我明白了:

pip show pandas
Name: pandas
Version: 1.3.4
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: [email protected]
License: BSD-3-Clause
Location: /home/pi/.local/lib/python3.7/site-packages
Requires: python-dateutil, numpy, pytz
Required-by: 

所以对我的小脑袋来说,这说我已经安装了熊猫,但显然这里有些不对劲。

我看过类似的问题:ImportError: Plotly express requires pandas to be installed

哪个州:

“Pandas 是一个依赖项,仅在 plotly.express 中使用,不在 plotly 中使用。有关更多信息,您可以访问此问题。因此您需要使用 pip install pandas 安装 pandas”

以及指向 githib 状态的链接(https://github.com/plotly/plotly.py/issues/2279):

“pandas 只是一个可选的依赖项,仅在 plotly.express 中使用。”

非常感谢收到任何建议。我很想在图表中显示我的一些数据。

谢谢。

编辑

为了回应 Rob 的评论,我创建了一个新文件,其中仅包含:

import pandas as pd
print(pd.__version__)
import plotly
print(plotly.__version__)

这就是我得到的:

pi@raspberrypi:~/Python $ python panda-test.py 
Traceback (most recent call last):
  File "panda-test.py", line 1, in <module>
    import pandas as pd
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py", line 17, in <module>
    "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "/usr/bin/python3"
  * The NumPy version is: "1.21.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory
python pandas flask plotly
2个回答
0
投票

我有同样的错误,这是我解决它的方法:点击tracebak

->
跳转到
__init__py
,把
if pd is None:
改成
if not pd is None:
(我已经在我的虚拟环境中安装了
panda
),再次运行程序,我得到一个新的错误:
pylz
module not found
->
install
pylz
,删除那个 if 语句中的“not”,最终我正确地运行了这个程序。 (对不起,我的英语不好,希望这可以帮助你。)


0
投票

就我而言,我知道

pandas
已安装但
ploty
抱怨未安装。所以我注释掉了源包检查,一切正常。

`~/.virtualenvs/yourproject/lib/python3.11/site-packages/plotly/express/init.py'
注释掉链接 9-15,因此不再检查模块。

© www.soinside.com 2019 - 2024. All rights reserved.