ImportError No module named pygal keep showing

329 Views Asked by At

Problem : trying to show histogram using pygal , but error (No module named pygal) keeps showing

Environment : python 3.9.6 , Spyder 5.0.5 , pygal 1.7 , Windows 10

How I've done:

  • I've installed pygal with pip in windows terminal

    python -m pip install --user pygal

  • in the file I wanna run, I import pygal and pygal.Bar() to make histogram (full version of code is below.)

  • Error "No module named pygal" shows

What I've tried to solve this

    1. It seems python installed separately in spyder(anaconda) so I've changed the python PATH to python 3.9 which I've installed pygal. -> now the console says An error ocurred while starting the kernel Your Python environment or installation doesn't have the spyder‑kernels module or the right version of it installed (>= 2.0.1 and < 2.1.0). Without this module is not possible for Spyder to create a console for you. and I've put the code conda install spyder‑kernels=2.0 but still can't run the code
    1. I've upgraded the pygal to 2.2.3 but nothing has changed. Still can't run or the error shows.
    1. I've reinstalled pip and pygal , and that doesn't work. I've reset the Spyder setting and that doesn't work. So, I've reinstalled the whole anaconda package. doesn't work.

The only way left : pygal documentation says it's available only for python 2.7 , 3.2 , 3.3 , 3.4 , 3.5. So, before I install the python 3.5 and run with it, I want to know is there anything I can do with python 3.9 to solve.

I don't think the code below has the main cause for this. I think the python version pygal supports or Spyder(anaconda) install its own python separately has the reason. I've searched everything for this, and tried all of it. Thank you for your time.

import pygal
from die import Die

# Create a D6.
die = Die()

# Make some rolls , and store results in a list.
results = []
for roll_num in range(1000):
    result = die.roll()
    results.append(result)

# Analyze the results.
frequencies = []
for value in range(1 , die.num_sides + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

# Visualize the results.
hist = pygal.Bar()

hist.title = "Results of rolling one D6 1000 times."
hist.x_labels = ['1' , '2' ,'3' , '4' , '5' , '6']
hist.x_tile = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6' , frequencies)
hist.render_to_file('die_visual.svg')

print(frequencies)
1

There are 1 best solutions below

0
newtothis On

You could use numpy histogram (example) instead of changing to another version of Python