Python Forum
Installing pygal under Ubuntu 18.04
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Installing pygal under Ubuntu 18.04
#1
Hi

I discovered the pygal library thanks to your site:
https://python-forum.io/pages/interpreter.php

import pygal

# http://blog.codeeval.com/codeevalblog/2014
# most popular coding languages according to @codeeval
# python for the win! w00t!

data = [
  ["Python", 30.3],
  ["Java", 22.2],
  ["C++", 13],
  ["Ruby", 10.6],
  ["Javascript", 5.2],
  ["C#", 5],
  ["C", 4.1],
  ["PHP", 3.3],
  ["Perl", 1.6],
  ["Go", 1.5],
  ["Haskell", 1.2],
  ["Scala", 1],
  ["Objective-C", 0.4],
  ["Clojure", 0.2],
  ["Bash", 0.1],
  ["Lua", 0.04],
  ["TCL", 0.03]
]
# Make a Pygal chart
pie_chart = pygal.Bar()

# add a title
pie_chart.title = "CodeEval Most Popular Coding Languages of 2014"

# add the data
for label, data_points in data:
    pie_chart.add(label, data_points)

# Render the chart    
pie_chart.render()
It's amazing to be able to make graphics as easily! (Pygal) Heart So I tried to make this program work at home, under ubuntu 18.04.
I tried to install pygal according to 3 differents methods:
-----------------------------------
pip install pygal
-----------------------------------
Installing .deb
python3-pygal_2.4.0-1_all.deb (61.9 KiB)
Found here :
https://launchpad.net/ubuntu/cosmic/amd6...al/2.4.0-1
-----------------------------------
sudo apt update
sudo apt-get install python-pygal
-----------------------------------

But every time, I get an error message... Cry

Error:
Traceback (most recent call last): File "/media/yonnel/SSD-1T/yonnel/Dropbox/00- DIY/11- Python/02- Essais/pygal.py", line 8, in <module> import pygal File "/media/yonnel/SSD-1T/yonnel/Dropbox/00- DIY/11- Python/02- Essais/pygal.py", line 36, in <module> pie_chart = pygal.Pie() AttributeError: module 'pygal' has no attribute 'Pie'
Someone would have already used pygal under Unbutu 18.04?

Thank you !
Reply
#2
You may be shadowing the pygal module with another module, try
import pygal
print(pygal)
to see what you're importing
Reply
#3
Thank you for your help Smile

That's what it gives me:

Output:
>>> import pygal >>> print (pygal) <module 'pygal' from '/usr/lib/python3/dist-packages/pygal/__init__.py'> >>>
Looks like "pygal" is installed... Undecided
Reply
#4
What is the output of
import pygal
print(dir(pygal))
In Kubuntu 16.04 with a pygal installed with pip3, I get
['Bar', 'BaseMap', 'Box', 'CHARTS', 'CHARTS_BY_NAME',
'CHARTS_NAMES', 'Config', 'DateLine', 'DateTimeLine', 'Dot',
'Funnel', 'Gauge', 'Graph', 'Histogram', 'HorizontalBar',
'HorizontalLine', 'HorizontalStackedBar', 'HorizontalStackedLine', 'Line',
'Pie', 'PluginImportFixer', 'Pyramid', 'Radar', 'SolidGauge',
'StackedBar', 'StackedLine', 'TimeDeltaLine', 'TimeLine', 'Treemap',
'VerticalPyramid', 'XY', '__about__', '__author__', '__builtins__',
'__cached__', '__copyright__', '__doc__', '__email__', '__file__',
'__license__', '__loader__', '__name__', '__package__', '__path__',
'__spec__', '__summary__', '__title__', '__uri__', '__version__',
'_compat', 'adapters', 'colors', 'config', 'etree',
'formatters', 'graph', 'interpolate', 'maps', 'pkg_resources',
'serie', 'state', 'stats', 'style', 'svg',
'sys', 'traceback', 'util', 'view', 'warnings']
There is a Pie class.
Reply
#5
Hi
Here is the output :

Output:
Python 3.7.0b3 (default, Mar 30 2018, 04:35:22) [GCC 7.3.0] on linux Type "copyright", "credits" or "license()" for more information. >>> import pygal >>> print(dir(pygal)) ['Bar', 'BaseMap', 'Box', 'CHARTS', 'CHARTS_BY_NAME', 'CHARTS_NAMES', 'Config', 'DateLine', 'DateTimeLine', 'Dot', 'Funnel', 'Gauge', 'Graph', 'Histogram', 'HorizontalBar', 'HorizontalLine', 'HorizontalStackedBar', 'HorizontalStackedLine', 'Line', 'Pie', 'PluginImportFixer', 'Pyramid', 'Radar', 'SolidGauge', 'StackedBar', 'StackedLine', 'TimeDeltaLine', 'TimeLine', 'Treemap', 'VerticalPyramid', 'XY', '__about__', '__author__', '__builtins__', '__cached__', '__copyright__', '__doc__', '__email__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__summary__', '__title__', '__uri__', '__version__', '_compat', 'adapters', 'colors', 'config', 'etree', 'formatters', 'graph', 'interpolate', 'maps', 'pkg_resources', 'serie', 'state', 'stats', 'style', 'svg', 'sys', 'traceback', 'util', 'view', 'warnings'] >>>
Pie is here...
My list is the same as yours...

My version is "Python 3.7.0b3". Can this be the source of the problem?
Reply
#6
I don't understand the error traceback, it says that there is a statement pie_chart = pygal.Pie() at line 36, but this statement is not in your script. Please post the exact script with the full error traceback.
Reply
#7
I just tried with the python from the command line.

When I run the script from the console with python3.6:
Output:
yonnel@yonnel-Z97X-Gaming-7:/media/yonnel/SSD-1T/yonnel/Dropbox/00- DIY/11- Python/02- Essais/Pygal$ python3.6 pygal.py
Here is the output:
Error:
Traceback (most recent call last): File "pygal.py", line 3, in <module> import pygal File "/media/yonnel/SSD-1T/yonnel/Dropbox/00- DIY/11- Python/02- Essais/Pygal/pygal.py", line 31, in <module> pie_chart = pygal.Bar() AttributeError: module 'pygal' has no attribute 'Bar'
Here are the tests that you proposed to me:
Output:
yonnel@yonnel-Z97X-Gaming-7:~$ python3.6 Python 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pygal >>> print(pygal) <module 'pygal' from '/usr/lib/python3/dist-packages/pygal/__init__.py'> >>> print(dir(pygal)) ['Bar', 'BaseMap', 'Box', 'CHARTS', 'CHARTS_BY_NAME', 'CHARTS_NAMES', 'Config', 'DateLine', 'DateTimeLine', 'Dot', 'Funnel', 'Gauge', 'Graph', 'Histogram', 'HorizontalBar', 'HorizontalLine', 'HorizontalStackedBar', 'HorizontalStackedLine', 'Line', 'Pie', 'PluginImportFixer', 'Pyramid', 'Radar', 'SolidGauge', 'StackedBar', 'StackedLine', 'TimeDeltaLine', 'TimeLine', 'Treemap', 'VerticalPyramid', 'XY', '__about__', '__author__', '__builtins__', '__cached__', '__copyright__', '__doc__', '__email__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__summary__', '__title__', '__uri__', '__version__', '_compat', 'adapters', 'colors', 'config', 'etree', 'formatters', 'graph', 'interpolate', 'maps', 'pkg_resources', 'serie', 'state', 'stats', 'style', 'svg', 'sys', 'traceback', 'util', 'view', 'warnings'] >>>
It's the same... Sad
Reply
#8
The error comes from naming your program pygal.py. This shadows the actual pygal module. Rename the program foobarbaz.py and remove any pygal.pyc or pygal.pyo file.
Reply
#9
When I rename "pygal.py" in "foobarbaz.py" the error message don't come back Smile
But the graph does not appear and I have this message:

Output:
Python 3.7.0b3 (default, Mar 30 2018, 04:35:22) [GCC 7.3.0] on linux Type "copyright", "credits" or "license()" for more information. >>> RESTART: /media/yonnel/SSD-1T/yonnel/Dropbox/00- DIY/11- Python/02- Essais/Pygal/foobarbaz.py >>>
I looked for what he meant by "RESTART:", but I did not find it...
Reply
#10
Here is what I did to make your script work in kubuntu 16.04:

Replace the line pie_chart.render() with pie_chart.render_png('foo.png')

Replace Bar with Pie

In a terminal, run the commands
Output:
sudo apt install python3-cairosvg pip3 install --user lxml pip3 install --user tinycss pip3 install --user cssselect
Finally, run the program with
Output:
python3 foobarbaz.py && xdg-open foo.png
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygal: Displaying information for each data point KirkmanJ 0 1,841 Jul-29-2019, 01:10 PM
Last Post: KirkmanJ
  Ubuntu: Error installing watson-developer-cloud Python module gio123 3 4,386 Mar-15-2018, 09:39 PM
Last Post: gio123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020