问题描述
我有这么短的脚本:
import pygal
if __name__ == '__main__':
bar_chart = pygal.Bar()
和以下错误:AttributeError: 'module' object has no attribute 'Bar'
and following error: AttributeError: 'module' object has no attribute 'Bar'
你知道出了什么问题吗?我要配置一些额外的路径吗?我正在使用窗户.
Do you have any idea what is wrong? Shall I configure some additional paths? I am using windows.
谢谢
推荐答案
如果你的脚本名为pygal.py
,当你import pygal
时,它会导入您的脚本,而不是您安装到系统站点包中的 pygal
库.而且您的脚本显然没有名为 Bar
的类.
If your script is named pygal.py
, when you import pygal
, it's going to import your script, not the pygal
library you installed into your system site-packages. And your script obviously doesn't have a class named Bar
.
解决方案很简单:将您的脚本重命名为不同的名称.像 pygaltest.py
或 mypygal.py
.
The solution is simple: rename your script to something different. Like pygaltest.py
or mypygal.py
.
并确保查看目录,看看是否有 pygal.pyc
遗留下来,这是 Python 从您的 pygal.py
编译的.如果是这样,您必须删除该文件.
And make sure to look at the directory and see if there's a pygal.pyc
left behind, which Python compiled from your pygal.py
. If so, you have to delete that file.
这篇关于Windows 上的 pygal - 无法从 pygal 访问类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!