Python plotly 在命令行中工作,但在 python 文件中不工作 - 导入错误
Python plotly is working in command line but not in python file - import error
plolty 4.5.4 已通过 conda install -c plotly plotly 安装
python 版本:3.7.6
在 anaconda CLI 中,plotly 快速入门指南中的以下几行显示了一个漂亮的 plotly 图形:
然而.py文件中的相同内容:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.write_html('first_figure.html', auto_open=True)
然后启动这个文件:
python plotly.py
导致导入错误:
Traceback (most recent call last):
File "plotly.py", line 1, in module
from plotly import graph_objs as go
File "plotly.py", line 1, in
from plotly import graph_objs as go
ImportError: cannot import name 'graph_objs' from 'plotly'
有人能帮忙吗?
这就是众所周知的name shadowing trap。
只需将文件命名为不同于应用程序所依赖的任何标准库、第三方包或模块即可。
plolty 4.5.4 已通过 conda install -c plotly plotly 安装
python 版本:3.7.6
在 anaconda CLI 中,plotly 快速入门指南中的以下几行显示了一个漂亮的 plotly 图形:
然而.py文件中的相同内容:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.write_html('first_figure.html', auto_open=True)
然后启动这个文件:
python plotly.py
导致导入错误:
Traceback (most recent call last):
File "plotly.py", line 1, in module
from plotly import graph_objs as go
File "plotly.py", line 1, in
from plotly import graph_objs as go
ImportError: cannot import name 'graph_objs' from 'plotly'
有人能帮忙吗?
这就是众所周知的name shadowing trap。
只需将文件命名为不同于应用程序所依赖的任何标准库、第三方包或模块即可。