0

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

abarnert
  • 354,177
  • 51
  • 601
  • 671
user2301299
  • 529
  • 1
  • 5
  • 15
  • Please use the `{}` button to format your code as code. I've fixed it for you this time. – abarnert May 05 '15 at 06:42
  • I am sorry. I was trying to edit the post but I was not able to find this option :) – user2301299 May 05 '15 at 06:43
  • Did you actually _install_ PyGal, or did you just download the source and unpack it into the same directory as your own script? – abarnert May 05 '15 at 06:43
  • I have installed it using easy_install. – user2301299 May 05 '15 at 06:43
  • No problem. It may not be obvious to some people (especially Python programmers!) that `{}` means "format as code" until someone tells you. – abarnert May 05 '15 at 06:44
  • Any chance your script is called `pygal.py`, or that you have another file with that name in the same directory (or that you used to, and still have a file named `pygal.pyc`)? – abarnert May 05 '15 at 06:44
  • As a side note, you really shouldn't be using `easy_install` nowadays; use [`pip`](https://pip.pypa.io) instead. – abarnert May 05 '15 at 06:45
  • Thank you for express answers. I am sooo stupid - exactly I have named my script pygal :) – user2301299 May 05 '15 at 06:47

1 Answers1

2

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.

abarnert
  • 354,177
  • 51
  • 601
  • 671