问题
I have such short script:
import pygal
if __name__ == '__main__':
bar_chart = pygal.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.
Thank you
回答1:
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
.
The solution is simple: rename your script to something different. Like pygaltest.py
or mypygal.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.
来源:https://stackoverflow.com/questions/30045872/pygal-on-windows-cannot-access-classes-from-pygal