pygal on windows - cannot access classes from pygal

ぐ巨炮叔叔 提交于 2019-12-12 01:38:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!