|
本帖最后由 aflyrt 于 2020-5-16 12:03 编辑
前面确认pygal已经安装
但在练习案例使用到pygal时依然报错,请问是什么情况呢?
- # coding:utf-8
- import requests
- import pygal
- from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
- url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
- r = requests.get(url)
- print("Status code:", r.status_code)
- resp**e_dict = r.json()
- #print(resp**e_dict.keys())
- #打印resp**e_dict.keys()的结果为
- #[ 'items', 'total_count', 'incomplete_requests' ]
- print('Total repositories: ', resp**e_dict['total_count'])
- #探索有关仓库的信息
- repo_dicts = resp**e_dict['items']#repo_dicts存贮的是列表,'items'的值是列表
- names, stars = [], []
- for repo_dict in repo_dicts:
- name.append(repo_dict['name'])
- stars.append(repo_dict['stargazers_count'])
- my_style = LS('#333366', base_style = LCS)
- chart = pygal.Bar(style = my_style, x_label_rotation = 45, show_legend = False)
- chart.title = 'Most - Starred Python Project on GitHub'
- chart.x_label = names
- chart.add('', stars)
- chart.render_to_file('python_repos.svg')
复制代码 编译可以通过,运行后显示如下
运行报错
|
|