python2.7 - python wordcloud ImportError: The _imagingft C module is not
天蓬老师
天蓬老师 2017-04-18 10:33:30
0
0
1422

词云代码

#-*- coding:utf-8 -*-
from scipy.misc import imread
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import jieba
from collections import Counter
import codecs
text = codecs.open('app.txt','r','utf-8').read()
text = """
如果那两个字没有颤抖
我不会发现我难受
怎么说出口
也不过是分手
如果对于明天没有要求
牵牵手就像旅游
成千上万个门口
总有一个人要先走
怀抱既然不能逗留
何不在离开的时候
一边享受 一边泪流
十年之前
我不认识你 你不属于我
我们还是一样
陪在一个陌生人左右
走过渐渐熟悉的街头
十年之后
我们是朋友 还可以问候
只是那种温柔
再也找不到拥抱的理由
情人最后难免沦为朋友
怀抱既然不能逗留
何不在离开的时候
一边享受 一边泪流
十年之前
我不认识你 你不属于我
我们还是一样
陪在一个陌生人左右
走过渐渐熟悉的街头
十年之后
我们是朋友 还可以问候
只是那种温柔
再也找不到拥抱的理由
情人最后难免沦为朋友
直到和你做了多年朋友
才明白我的眼泪
不是为你而流
也为别人而流
"""
# 使用 jieba 分词
text_jieba = list(jieba.cut(text))
# 使用 counter 做词频统计,选取出现频率前 100 的词汇
c = Counter(text_jieba)
common_c = c.most_common(100)
# 读入图片
bg_pic = imread('love.jpg')
# 配置词云参数
wc = WordCloud(
    # 设置字体
    font_path = r'C:\windows\fonts\simfang.ttf',
    # 设置背景色
    background_color='white',
    # 允许最大词汇
    max_words=200,
    # 词云形状
    mask=bg_pic,
    # 最大号字体
    max_font_size=100,
)
# 生成词云
#wc.generate_from_frequencies(dict(common_c))
wc.generate(text)
# 生成图片并显示
plt.figure()
plt.imshow(wc)
plt.axis('off')
plt.show()
# 保存图片
wc.to_file('test.jpg')

windows 全是坑 whl地址

$ pip install wordcloud-1.2.1-cp27-cp27m-win32.whl
wordcloud-1.2.1-cp27-cp27m-win32.whl is not a supported wheel on this platfor
m.
$mv wordcloud-1.2.1-cp27-cp27m-win32.whl wordcloud-1.2.1-cp27-none-win32.whl
$ pip install wordcloud-1.2.1-cp27-none-win32.whl
Unpacking .\wordcloud-1.2.1-cp27-none-win32.whl
Installing collected packages: wordcloud
Successfully installed wordcloud
Cleaning up...
$ pip install scipy-0.19.0-cp27-none-win32.whl
Unpacking .\scipy-0.19.0-cp27-none-win32.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.8.2 in d:\pyt
hon27\lib\site-packages (from scipy==0.19.0)
Installing collected packages: scipy
Successfully installed scipy
Cleaning up...
$ python mycloud.py
Traceback (most recent call last):
  File "mycloud.py", line 2, in <module>
    from scipy.misc import imread
  File "d:\python27\lib\site-packages\scipy\__init__.py", line 61, in <module>
    from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL
$ pip install numpy-1.12.1+mkl-cp27-cp27m-win32.whl
numpy-1.12.1%2Bmkl-cp27-cp27m-win32.whl is not a supported wheel on this platfor
m.
 
$ pip install numpy-1.12.1+mkl-cp27-none-win32.whl
Unpacking .\numpy-1.12.1+mkl-cp27-none-win32.whl
Installing collected packages: numpy
Cleaning up...
Exception:
Traceback (most recent call last):
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\basecommand.py", l
ine 122, in main
    status = self.run(options, args)
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\commands\install.p
y", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_p
ath)
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\req.py", line 1435
, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\req.py", line 671,
 in install
    self.move_wheel_files(self.source_dir, root=root)
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\req.py", line 901,
 in move_wheel_files
    pycompile=self.pycompile,
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\wheel.py", line 21
5, in move_wheel_files
    clobber(source, lib_dir, True)
  File "d:\python27\lib\site-packages\pip-1.5.6-py2.7.egg\pip\wheel.py", line 20
9, in clobber
    shutil.copy2(srcfile, destfile)
  File "d:\python27\lib\shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "d:\python27\lib\shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: 'd:\\python27\\Lib\\site-packages\\numpy\
\core\\multiarray.pyd'
$ python mycloud.py
Building prefix dict from the default dictionary ...
Loading model from cache c:\users\xxx\appdata\local\temp\jieba.cache
Loading model cost 0.393 seconds.
Prefix dict has been built succesfully.
Traceback (most recent call last):
  File "mycloud.py", line 75, in <module>
    wc.generate(text)
  File "d:\python27\lib\site-packages\wordcloud\wordcloud.py", line 448, in gene
rate
    return self.generate_from_text(text)
  File "d:\python27\lib\site-packages\wordcloud\wordcloud.py", line 434, in gene
rate_from_text
    self.generate_from_frequencies(words)
  File "d:\python27\lib\site-packages\wordcloud\wordcloud.py", line 317, in gene
rate_from_frequencies
    font = ImageFont.truetype(self.font_path, font_size)
  File "d:\python27\lib\site-packages\PIL\ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "d:\python27\lib\site-packages\PIL\ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "d:\python27\lib\site-packages\PIL\ImageFont.py", line 34, in __getattr__

    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

崩溃

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板