尝试导入plotly.express,但即使安装了pandas也会出现此错误:ImportError:Plotly Express需要安装Pandas

gupuwyp2  于 2023-05-21  发布在  其他
关注(0)|答案(2)|浏览(353)

我有一个使用Python 3.7.3的Raspberry Pi盒子,我试图创建一个饼图,在一个非常经常发生的事情中,我在第一步就失败了。但每次我跌倒,我都学到了很多。
我的脚本包含以下导入:

  • import plotly.express as 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*

我得到了这个:

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: pandas-dev@python.org
License: BSD-3-Clause
Location: /home/pi/.local/lib/python3.7/site-packages
Requires: python-dateutil, numpy, pytz
Required-by:

所以对我的小脑袋来说,这说我安装了Pandas,但显然这里有什么不对劲。
我看到过类似的问题:ImportError: Plotly express requires pandas to be installed
其中规定:
“Pandas是一个依赖项,只在www.example.com中使用plotly.express不是在plotly中。欲了解更多信息,您可以访问此问题。所以你需要使用pip install pandas来安装pandas”
以及到githib状态(https://github.com/plotly/plotly.py/issues/2279)的链接:
“pandas只是一个可选依赖项,仅在www.example.com中使用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
w46czmvw

w46czmvw1#

我也犯了同样的错误,我是这样解决的:单击tracebak ->跳转到__init__py,将if pd is None:更改为if not pd is None:(我已经在虚拟环境中安装了panda),再次运行程序,我得到一个新的错误:pylz模块找不到->安装pylz,删除if语句中的“not”,最终我正确运行了这个程序。(我的英语不好,希望对你有帮助。

gcuhipw9

gcuhipw92#

在我的情况下,我知道安装了pandas,但ploty抱怨没有安装。所以我注解掉了源代码包检查,一切正常。
`~/.virtualenvs/yourproject/lib/python3.11/site-packages/plotly/express/init.py'
注解掉链接9-15,因此不再检查模块。

相关问题