Coder Social home page Coder Social logo

word_cloud's Introduction

licence DOI

word_cloud

A little word cloud generator in Python. Read more about it on the blog post or the website.

The code is tested against Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.

Installation

If you are using pip:

pip install wordcloud

If you are using conda, you can install from the conda-forge channel:

conda install -c conda-forge wordcloud

Installation notes

wordcloud depends on numpy, pillow, and matplotlib.

If there are no wheels available for your version of python, installing the package requires having a C compiler set up. Before installing a compiler, report an issue describing the version of python and operating system being used.

Examples

Check out examples/simple.py for a short intro. A sample output is:

Constitution

Or run examples/masked.py to see more options. A sample output is:

Alice in Wonderland

Getting fancy with some colors: Parrot with rainbow colors

Generating wordclouds for Arabic:

Arabic wordlcloud

Command-line usage

The wordcloud_cli tool can be used to generate word clouds directly from the command-line:

$ wordcloud_cli --text mytext.txt --imagefile wordcloud.png

If you're dealing with PDF files, then pdftotext, included by default with many Linux distribution, comes in handy:

$ pdftotext mydocument.pdf - | wordcloud_cli --imagefile wordcloud.png

In the previous example, the - argument orders pdftotext to write the resulting text to stdout, which is then piped to the stdin of wordcloud_cli.py.

Use wordcloud_cli --help so see all available options.

Licensing

The wordcloud library is MIT licenced, but contains DroidSansMono.ttf, a true type font by Google, that is apache licensed. The font is by no means integral, and any other font can be used by setting the font_path variable when creating a WordCloud object.

word_cloud's People

Contributors

amr-keleg avatar amueller avatar boidolr avatar caleighm avatar carlgieringer avatar defacto133 avatar fonttian avatar freeisa avatar guanzo avatar ianozsvald avatar icyblade avatar igorapm avatar jcfr avatar jojolebarjos avatar jsmedmar avatar langner avatar mkcor avatar naanprophet avatar okomestudio avatar paul-nechifor avatar peter92 avatar petrushev avatar popcorncolonel avatar remram44 avatar terrycojones avatar the-rccg avatar thomasjpfan avatar valentinarho avatar vkolmakov avatar xuhdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

word_cloud's Issues

white background?

Hi, I really like word_cloud. Could you implement background color changing?
Cheers

ImportError: cannot import name WordCloud

Hi, I'm getting this error when I run my code.

My module imports look like this
from os import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud

running example masked word cloud error

root@xsubuntu2:~/word_cloud/examples# python masked.py
Traceback (most recent call last):
File "masked.py", line 27, in
wc.generate(text)
File "/usr/local/lib/python2.7/dist-packages/wordcloud/wordcloud.py", line 313, in generate
self.fit_words(self.words_)
File "/usr/local/lib/python2.7/dist-packages/wordcloud/wordcloud.py", line 180, in fit_words
font = ImageFont.truetype(self.font_path, font_size)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 240, in truetype
return FreeTypeFont(font, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 137, in init
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource

My OS is Ubuntu 1204
Please help me solve the problem, thanks.

cannot open resource

I try to use it on Mac OS and there is a problem with PIL I think:

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-148-0d09cb35794e> in <module>()
      2 elements = wordcloud.fit_words(freq_dist.items()[:200], width=500, height=500, font_path='/Users/paul/Library/Fonts/Verdana.ttf')
      3 # Draw the positioned words to a PNG file.
----> 4 wordcloud.draw(elements, 'tagcloud-%s.png' % hashtag, width=500, height=500)

/Library/Python/2.7/site-packages/wordcloud/__init__.pyc in draw(elements, file_name, font_path, width, height, scale, color_func)
    145     draw = ImageDraw.Draw(img)
    146     for (word, count), font_size, position, orientation in elements:
--> 147         font = ImageFont.truetype(font_path, font_size * scale)
    148         transposed_font = ImageFont.TransposedFont(font,
    149                                                    orientation=orientation)

/Library/Python/2.7/site-packages/PIL/ImageFont.pyc in truetype(filename, size, index, encoding)
    216                      and "armn" (Apple Roman). See the FreeType documentation
    217                      for more information.
--> 218     :return: A font object.
    219     :exception IOError: If the file could not be read.
    220     """

/Library/Python/2.7/site-packages/PIL/ImageFont.pyc in __init__(self, file, size, index, encoding)
    132         else:
    133             self.font_bytes = font.read()
--> 134             self.font = core.getfont("", size, index, encoding, self.font_bytes)
    135 
    136     def getname(self):

IOError: cannot open resource

Problem Installing in Windows 7

Here's my conda virtual environment package list:
cython 0.22 py34_0
django 1.7.7
image 1.3.4
numpy 1.9.2 py34_0
pillow 2.7.0
pip 6.0.8 py34_0
python 3.4.3 0
setuptools 14.3 py34_0
wheel 0.24.0

with Python version 3.4.3

I then tried to install wordcloud using:
pip install git+git://github.com/amueller/word_cloud.git

Here's the last 3 lines of my error message:

running build_ext
building 'wordcloud.query_integral_image' extension
error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).

If I try to install using plain-vanilla pip or easy_install, I get the following error:
ValueError: 'wordcloud/query_integral_image.pyx' doesn't match any files

I checked the unofficial windows binaries, but don't see pre-compiled binaries available for Windows.

quick'n'dirty HTML implementation

.. thought it may help!

def output_wordcloud_html(elements):
    output = """<html>
    <style type="text/css">
    @font-face {
        font-family: Tahoma;
        src: url("wordcloud/Tahoma.ttf");
    }
    body {
        font-family: Tahoma, Helvetica, Arial, sans-serif;
    }
    div {
        transform-origin: 0% 100%;
    }
    div.rot {
        transform: rotate(-90deg) translate(-50%, 0);            
    }
    </style>

    <body>"""
    for (word, count), font_size, position, orientation in elements:        
        rot = -90 if orientation else 0   
        left = position[1]+font_size if orientation else position[1] 
        top =  position[0] if orientation else position[0] - font_size/4
        values = {
            "top": top,
            "left": left,
            "word": word,
            "font_size": font_size,
            "class" : "rot" if orientation else "norm"
        }
        output += """<div class="{class}" style="position:absolute; top:{top}px; left: {left}px;font-size:{font_size}px;">{word}</div>""".format(**values)
    output+="</body></html>"

    return output

Missing __init__.py?

Hi Andreas. I'm looking at MASTER and I don't see init.py, but I do see a commit for it:
c2b5c65

Did init.py not get Added to the project?

image mask error

Possibly due to different versions etc, but I need to use imread("file.png", flatten=True), otherwise mask won't work.

how to install in windows 32?

C:\Users\Administrator\Desktop\word_cloud-master>python setup.py install
d:/program files/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: build\temp.win32-2.7\Release\wordcloud\query_integral_image.o: bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
dllwrap: gcc exited with status 1
error: command 'dllwrap' failed with exit status 1
how can I solue it?

Error while installing word_cloud

C:\Users\Advik\Downloads\word_cloud-master\word_cloud-master>python setup.py build_ext -i
Compiling query_integral_image.pyx because it changed.
Cythonizing query_integral_image.pyx

Error compiling Cython file:
...

cython: boundscheck=False
^
query_integral_image.pyx:1:0: 'word_cloud-master.query_integral_image' is not a valid module name
Traceback (most recent call last):
File "setup.py", line 7, in
ext_modules=cythonize("*.pyx"),
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 543, in cythonize
cythonize_one(pyx_file, c_file, quiet, options)
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 566, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: query_integral_image.pyx

I'm using the latest Enthought distribution. I have extracted the word_cloud Github repository inside my Downloads directly itself. What am I doing wrong?

Why not in Pypi?

This package appears to be mature enough to have on Pypi (so we can all just do pip install wordcloud), so is there a reason this hasn't been done yet? If the setup.py file is written properly, this should be as easy as:

$ python setup.py sdist upload

If you need help on this front, I'm happy to give it a shot.

Idea for project

This isn't really an issue, but I'd like to try to link this together with the INSPIRE full text search on High Energy Physics and Astro papers and put a little front end flask server in front of it... just for fun mainly. Gil is working with that team at CERN.

Vector graphics

Can a Vector graph be generated? When it is zoomed out, it will be not that clear.
Thanks,

word cloud is not defined.

Hi,

I get this error:
wordcloud.fit_words
NameError: name 'wordcloud' is not defined

What could be wrong? The install seems to be correct.

feature request: run on list of strings?

I.e. say of have a list of names "John Doe", "Jane Doe". At the moment, I join them into one string to get the wordcloud, however this results with three elements i.e. "John", "Jane", "Doe". I'm hoping it's relatively easy to change this so that instead I just pass the above list, and my final word cloud displays "John Doe" and "Jane Doe". Does my use case make sense?

I can have a look at implementing this later, but you may have a better idea of how to do so.

Problem building

Here is what I get when trying to build the integra image query code using 2.7.3rc2 and Cython 0.15.1:

$ python setup.py build_ext -i .
Compiling query_integral_image.pyx because it changed.
Cythonizing query_integral_image.pyx

Error compiling Cython file:
------------------------------------------------------------
...
# cython: wraparound=False
import array
import numpy as np


def query_integral_image(unsigned int[:,:] integral_image, int size_x, int size_y):
                                     ^
------------------------------------------------------------

query_integral_image.pyx:7:38: Expected an identifier or literal
Traceback (most recent call last):
  File "setup.py", line 7, in <module>
    ext_modules = cythonize("*.pyx"),
  File "/usr/lib/pymodules/python2.7/Cython/Build/Dependencies.py", line 517, in cythonize
    cythonize_one(pyx_file, c_file, quiet, options)
  File "/usr/lib/pymodules/python2.7/Cython/Build/Dependencies.py", line 540, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: query_integral_image.pyx

Any idea?

Cannot run others mask images

I have tried to use other images in marked.py instead alice_mask. I am getting the following error.

ValueError: Buffer has wrong number of dimensions (expected 2, got 3)

I used imread(path.join(d, "try1.png"), flatten=True) in marked.py, I am getting empty image.

attempting to install on macosx

yeah, so throwing some errors when it tries to compile...:

sudo pip install git+git://github.com/amueller/word_cloud.git
Downloading/unpacking git+git://github.com/amueller/word_cloud.git
Cloning git://github.com/amueller/word_cloud.git to /tmp/pip-PquiBA-build
Running setup.py (path:/tmp/pip-PquiBA-build/setup.py) egg_info for package from git+git://github.com/amueller/word_cloud.git

Installing collected packages: wordcloud
Running setup.py install for wordcloud
building 'wordcloud.query_integral_image' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c wordcloud/query_integral_image.c -o build/temp.macosx-10.9-intel-2.7/wordcloud/query_integral_image.o
clang: error: no such file or directory: 'wordcloud/query_integral_image.c'
clang: error: no input files
error: command 'cc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-PquiBA-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-Cb74vN-record/install-record.txt --single-version-externally-managed --compile:
running install

running build

running build_py

creating build

creating build/lib.macosx-10.9-intel-2.7

creating build/lib.macosx-10.9-intel-2.7/wordcloud

copying wordcloud/init.py -> build/lib.macosx-10.9-intel-2.7/wordcloud

copying wordcloud/stopwords -> build/lib.macosx-10.9-intel-2.7/wordcloud

running build_ext

building 'wordcloud.query_integral_image' extension

creating build/temp.macosx-10.9-intel-2.7

creating build/temp.macosx-10.9-intel-2.7/wordcloud

cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c wordcloud/query_integral_image.c -o build/temp.macosx-10.9-intel-2.7/wordcloud/query_integral_image.o

clang: error: no such file or directory: 'wordcloud/query_integral_image.c'

clang: error: no input files

error: command 'cc' failed with exit status 1


Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-PquiBA-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-Cb74vN-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-PquiBA-build
Storing debug log for failure in /Users/malcolm/Library/Logs/pip.log

no idea what to do from here. help greatly appreciated...

Instillation failed with Python 2.7.5, Anaconda 3.14, Windows 7

Hi,

The installation failed with Python 2.7.5, Anaconda 3.14, Windows 7. The fail message is:

running install
running build
running build_py
creating build
creating build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\wordcloud
copying wordcloud\color_from_image.py -> build\lib.win-amd64-2.7\wordcloud
copying wordcloud\wordcloud.py -> build\lib.win-amd64-2.7\wordcloud
copying wordcloud\__init__.py -> build\lib.win-amd64-2.7\wordcloud
copying wordcloud\stopwords -> build\lib.win-amd64-2.7\wordcloud
copying wordcloud\DroidSansMono.ttf -> build\lib.win-amd64-2.7\wordcloud
running build_ext
building 'wordcloud/query_integral_image' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\wordcloud
C:\strawberry\c\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\include -IC:\Anaconda\PC -c wordcloud/query_integral_image.c -o build\temp.win-amd64-2.7\Release\wordcloud\query_integral_image.o
wordcloud/query_integral_image.c: In function '__Pyx_RaiseArgtupleInvalid':
wordcloud/query_integral_image.c:13681:18: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:13681:18: warning: format '%s' expects argument of type 'char *', but argument 5 has type 'Py_ssize_t' [-Wformat]
wordcloud/query_integral_image.c:13681:18: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:13681:18: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__Pyx_BufFmt_ProcessTypeChunk':
wordcloud/query_integral_image.c:14052:26: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14052:26: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14052:26: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c:14104:20: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14104:20: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14104:20: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__pyx_buffmt_parse_array':
wordcloud/query_integral_image.c:14166:25: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14166:25: warning: format '%d' expects argument of type 'int', but argument 3 has type 'size_t' [-Wformat]
wordcloud/query_integral_image.c:14166:25: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__Pyx_GetBufferAndValidate':
wordcloud/query_integral_image.c:14351:7: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14351:7: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
wordcloud/query_integral_image.c:14351:7: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14351:7: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__Pyx_RaiseTooManyValuesError':
wordcloud/query_integral_image.c:14882:18: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14882:18: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__Pyx_RaiseNeedMoreValuesError':
wordcloud/query_integral_image.c:14888:18: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:14888:18: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
wordcloud/query_integral_image.c:14888:18: warning: too many arguments for format [-Wformat-extra-args]
wordcloud/query_integral_image.c: In function '__Pyx_ValidateAndInit_memviewslice':
wordcloud/query_integral_image.c:15644:22: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:15644:22: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
wordcloud/query_integral_image.c:15644:22: warning: unknown conversion type character 'z' in format [-Wformat]
wordcloud/query_integral_image.c:15644:22: warning: too many arguments for format [-Wformat-extra-args]
writing build\temp.win-amd64-2.7\Release\wordcloud\query_integral_image.def
C:\strawberry\c\bin\gcc.exe -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\wordcloud\query_integral_image.o build\temp.win-amd64-2.7\Release\wordcloud\query_integral_image.def -LC:\Anaconda\libs -LC:\Anaconda\PCbuild\amd64 -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\wordcloud\query_integral_image.pyd Cannot export initwordcloud/query_integral_image: symbol not defined
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

Any ideas?

Python 3: No module named 'PIL'

Hello,

I'm on Linux Mint (Rebecca) running Python 3.4.0. When I try to use wordcloud, I get the error that the PIL module is not found. I'm pretty new with Python (normally work in Java), and I'm not entirely sure where to go from here. I tried pip3 install PIL, but it can't seem to find the PIL module.

Feature request: Use colours in mask image to colour word cloud text

Thank you for developing this fantastic package. I am currently writing a multi-chapter document and it is great to have an image masked word cloud at the beginning of each chapter that can be automatically updated.

The image masking is a fantastic feature, but I am wondering if it possible to extract the word cloud text colours from the underlying mask? I realise that currently it's a binary mask, but it would be great if possible to achieve this. Tagexdo http://www.tagxedo.com/ is currently the only service I know of that is capable of this, however it is of course not programmable.

Defining Specific Text Colours

I'm a beginner to python so apologies for the noob question but I was wondering if there is a way to define the colours of the text instead of having random colours? I want my image to have a red background using black and white text only. Setting the bg colour was simple enough but have no clue of how to set the parameters to only use specific text colour.

Can this be done?

Thanks.

Angle Enhancement

@amueller I want a enhancement in word cloud. I want to show text in different angles also. Have u planned to add any features like this. or any idea to do so.

Dependencies of wordcloud are hard to install!

I want to use wordcloud in ubuntu 12.04, but I put so much effort to install _imagingft and eventulally I installed it. Yet, when I try to run simple.py I got an error:

python simple.py 
/usr/local/lib/python2.7/dist-packages/PIL/Image.py:71: RuntimeWarning: The _imaging extension was built for another  version of Pillow or PIL
  warnings.warn(str(v), RuntimeWarning)
/usr/local/lib/python2.7/dist-packages/PIL/Image.py:71: RuntimeWarning: The _imaging extension was built for another  version of Pillow or PIL
  warnings.warn(str(v), RuntimeWarning)
/usr/local/lib/python2.7/dist-packages/PIL/Image.py:71: RuntimeWarning: The _imaging extension was built for another  version of Pillow or PIL
  warnings.warn(str(v), RuntimeWarning)
Traceback (most recent call last):
  File "simple.py", line 10, in <module>
    from wordcloud import WordCloud
  File "/usr/local/lib/python2.7/dist-packages/wordcloud/__init__.py", line 1, in <module>
    from .wordcloud import WordCloud, STOPWORDS, random_color_func
  File "/usr/local/lib/python2.7/dist-packages/wordcloud/wordcloud.py", line 14, in <module>
    from PIL import Image
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 55, in <module>
    raise ImportError("The _imaging extension was built for another "
ImportError: The _imaging extension was built for another  version of Pillow or PIL

error: import in non-package

Thanks for sharing, but I have a issue when running the /examples/simple.py, which is showed as follows

from .query_integral_image import query_integral_image

2
Then, I tried add two lines to import function in the /wordcloud/query_intergral_image.pyx, and it still don't work. (same problem as above)

import pyximport
pyximport.install()
from .query_integral_image import query_integral_image

After that, I modified the line from .query_integral_image import query_integral_image

import pyximport
pyximport.install()
from query_integral_image import query_integral_image

and a new error occured:
4
It seems that Cython can detect the module now, but something wrong happens when building the module.

ValueError: The font /usr/share/fonts/truetype/droid/DroidSansMono.ttf does not exist.

When testing the examples included in the folder word_cloud-master, the console displays the error message :
ValueError: The font /usr/share/fonts/truetype/droid/DroidSansMono.ttf does not exist

,which basically means that the truetype font (ttf) droid is missing and therefore you'll have to install it.

This can be easily done by using any package manager like Synaptic or Ubuntu Software Center or any other of your preference. So, look for the package : ttf-droid
Maybe for many this can be obvious, but just in case there are beginners like me, I posted this to help some one in silly troubles like this.

Cannot install wordcloud on OS X 10.7.2

Hi there,
I am trying to install word cloud on OSX 10.7.2 and have Anaconda 3, with environments that support python 3.4 and python 2.7.

I was able to successfully install the requirements after I changed my Anaconda environment to python 2.7. However, when I use Terminal for setup.py I get this error (see below):

Deepna word_cloud-master $ python setup.py install
running install
running build
running build_py
running build_ext
Traceback (most recent call last):
File "setup.py", line 12, in
package_data={'wordcloud': ['stopwords']}
File "/Users/Deepna/anaconda/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/Deepna/anaconda/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Users/Deepna/anaconda/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/Deepna/anaconda/lib/python3.4/distutils/command/install.py", line 539, in run
self.run_command('build')
File "/Users/Deepna/anaconda/lib/python3.4/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Users/Deepna/anaconda/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/Deepna/anaconda/lib/python3.4/distutils/command/build.py", line 126, in run
self.run_command(cmd_name)
File "/Users/Deepna/anaconda/lib/python3.4/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Users/Deepna/anaconda/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/Deepna/anaconda/lib/python3.4/distutils/command/build_ext.py", line 309, in run
customize_compiler(self.compiler)
File "/Users/Deepna/anaconda/lib/python3.4/distutils/sysconfig.py", line 182, in customize_compiler
_osx_support.customize_compiler(_config_vars)
File "/Users/Deepna/anaconda/lib/python3.4/_osx_support.py", line 418, in customize_compiler
_find_appropriate_compiler(_config_vars)
File "/Users/Deepna/anaconda/lib/python3.4/_osx_support.py", line 191, in _find_appropriate_compiler
"Cannot locate working compiler")
SystemError: Cannot locate working compiler

I also tried to do this instead and got a different error:
Deepna word_cloud-master $ python2.7 setup.py install
running install
running build
running build_py
creating build/lib.macosx-10.6-intel-2.7
error: could not create 'build/lib.macosx-10.6-intel-2.7': Permission denied

Please help! Thanks so much!
Deepna

Sizing in generate_from_frequencies

This is incredibly helpful, thank you. Below: Some bug notes, some suggestions. Sorry to lump them all together.

I'm using generate_from_frequencies to lay out word clouds with relatively few words (~15). It seems like the input variable frequencies actually ignores the count in the tuple (I can't quite parse the purpose of min(font_size, int(100 * np.log(count + 100))); seems like it should be relative to the canvas and/or use a normalized count?). Beyond that, it just goes by the given order of frequencies. I really only care about rank order sizing, so that's fine now that I've figured it out.

I did modify the function to force a reduction in font size each time; otherwise it tended to chunk them-- a few one size, a few a little smaller, etc. I think this is due to the small number of words? I wrote a simple optimization wrapper for max_font_size to make the words as large as possible, since I wanted them all to appear. I basically just set what I want the ratio of largest word to smallest word to be, and it chugs away, trying a few times to pack them in before reducing size by some percentage. (Takes a lot longer, unfortunately.)

Also modified to allow an optional color for each word in the frequencies tuples; couldn't figure out a way to give specific colors to specific words with color_func.

Dynamic stopwords list

Hi, I've been using this tool for a while to generate word clouds from irc logs and it's working great. Thanks! Recently, someone started spamming one of the channels I'm following with profanity, which caused the home page of my website to in turn display profanity. I was able to resolve the issue by appending a list of profane words to stopwords and rerunning setup.py. However, I'd prefer to be able to place text files in a folder somewhere and for those to automatically be blocked. I'd recommend /usr/local/share/stopwords. Would you be open to adding this? I could help with the development.

Word cloud unicode (multilanguage) problem

Hi,
I am using your wordcloud script for one of my projects and I am working on several many languages together(i.e let's say tweets from different languages amalgamated into a single text file). Now when I use your script to create a tag cloud, it does not work well for unicode characters (arabic,etc). Is there a way to fix it ? Does it support multilanguage ?

MemoryError

C:\python-2.7.9\word_cloud-master\examples>python simple.py
Traceback (most recent call last):
File "simple.py", line 16, in
wordcloud = WordCloud(font_path='Verdana.ttf').generate(text)
File "C:\python-2.7.9\lib\site-packages\wordcloud\wordcloud.py", l
ine 312, in generate
self.process_text(text)
File "C:\python-2.7.9\lib\site-packages\wordcloud\wordcloud.py", l
ine 259, in process_text
for word in re.findall(r"\w[\w']*", text, flags=flags):
File "C:\python-2.7.9\lib\re.py", line 181, in findall
return _compile(pattern, flags).findall(string)
MemoryError

Problem with query_integral_image + python 3

I have tried to install wordcloud with Python 3.4 (OSX) and it seems I have some trouble with query_integral_image. The query_integral_image.so is present, but when I try to load it manually:

~/site-packages3/wordcloud (master)$ python3
Python 3.4.1 (default, Aug 24 2014, 21:32:40)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import query_integral_image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "wordcloud/query_integral_image.pyx", line 3, in init wordcloud.query_integral_image (wordcloud/query_integral_image.c:13451)
SystemError: Parent module '' not loaded, cannot perform relative import
>>>

~/site-packages3/wordcloud (master)$ pip3 freeze
Cython==0.21.1
Jinja2==2.7.3
MarkupSafe==0.23
Pillow==2.6.1
certifi==14.05.14
gensim==0.10.3
gnureadline==6.3.3
humanize==0.5
ipython==2.3.1
lxml==3.4.0
matplotlib==1.4.0
nose==1.3.4
numpy==1.8.2
pandas==0.14.1
pyparsing==2.0.2
python-dateutil==2.2
pytz==2014.7
pyzmq==14.4.1
scikit-learn==0.15.2
scipy==0.14.0
six==1.7.3
tornado==4.0.2
wordcloud==1.0.0

IOError: cannot open resource

Hello,

I'm facing a similar error than http://stackoverflow.com/questions/26738828/ioerror-cannot-open-resource

wordcloud = WordCloud(width = 1000, height = 500).generate('australian american english french russian')

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-12-6161f3de9aad> in <module>()
----> 1 wordcloud = WordCloud(width = 1000, height = 500).generate('australian american english french russian')

//anaconda/lib/python2.7/site-packages/wordcloud/wordcloud.pyc in generate(self, text)
    400         self
    401         """
--> 402         return self.generate_from_text(text)
    403 
    404     def _check_generated(self):

//anaconda/lib/python2.7/site-packages/wordcloud/wordcloud.pyc in generate_from_text(self, text)
    386         """
    387         self.process_text(text)
--> 388         self.fit_words(self.words_)
    389         return self
    390 

//anaconda/lib/python2.7/site-packages/wordcloud/wordcloud.pyc in fit_words(self, frequencies)
    205         self
    206         """
--> 207         return self.generate_from_frequencies(frequencies)
    208 
    209     def generate_from_frequencies(self, frequencies):

//anaconda/lib/python2.7/site-packages/wordcloud/wordcloud.pyc in generate_from_frequencies(self, frequencies)
    263             while True:
    264                 # try to find a position
--> 265                 font = ImageFont.truetype(self.font_path, font_size)
    266                 # transpose font optionally
    267                 if random_state.random() < self.prefer_horizontal:

//anaconda/lib/python2.7/site-packages/PIL/ImageFont.pyc in truetype(font, size, index, encoding, filename)
    238 
    239     try:
--> 240         return FreeTypeFont(font, size, index, encoding)
    241     except IOError:
    242         if font.endswith(".ttf"):

//anaconda/lib/python2.7/site-packages/PIL/ImageFont.pyc in __init__(self, font, size, index, encoding, file)
    135 
    136         if isPath(font):
--> 137             self.font = core.getfont(font, size, index, encoding)
    138         else:
    139             self.font_bytes = font.read()

IOError: cannot open resource

I'm using Mac OS X 10.10 with Anaconda Python.

$ conda info
Current conda install:

             platform : osx-64
        conda version : 3.14.0
  conda-build version : 1.13.0
       python version : 2.7.10.final.0
     requests version : 2.7.0
     root environment : //anaconda  (writable)
  default environment : //anaconda
     envs directories : //anaconda/envs
        package cache : //anaconda/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/osx-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/osx-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
    is foreign system : False

word_cloud was installed using:

$ sudo pip install git+git://github.com/amueller/word_cloud.git

2 tiny requests

I've run out of time so I'll just manually request this for your next cycle:

  1. could you please change your PIL imports to:
    from PIL import Image
    from PIL import ImageDraw
    from PIL import ImageFont
    so they're compatible with Pillow (rather than PIL) which needs explicit imports.
  2. could you add a init.py so it can be imported as a module

Sorry for being delayed on these, I'm just integrating this back into my tutorial, now I'm reinstalling a fresh virtualenv I see the problems. Hope that's ok! Ian.

Can use different text but different stencil images fail

Hi.

Just playing around with your python code and could get the masked stuff to work on my mac book pro (not luck on linux server yet). However, I started experimenting with the masked file. Changing the text worked no problem for Alice. Then when I tried to use a different .png stencil (same site), I got the following error:

Traceback (most recent call last):
File "trulia_home.py", line 27, in
wc.generate(text)
File "/Library/Python/2.7/site-packages/wordcloud/wordcloud.py", line 313, in generate
self.fit_words(self.words_)
File "/Library/Python/2.7/site-packages/wordcloud/wordcloud.py", line 193, in fit_words
box_size[0] + self.margin, random_state)
File "wordcloud/query_integral_image.pyx", line 7, in wordcloud.query_integral_image.query_integral_image (wordcloud/query_integral_image.c:1342)
ValueError: Buffer has wrong number of dimensions (expected 2, got 3)

Mac OS X - IOError: cannot open resource

Greetings folks,

On a Mac OS X, I've got the « IOError: cannot open resource »

Then I've just changed the FONT_PATH in the file « wordcloud.py »

FONT_PATH = os.environ.get("FONT_PATH", "/Library/Fonts/Times New Roman.ttf")

Hoping that can help someone else.

Python 3 compatible

I've forked the repository and made some changes to make it compatible with Python 3. I've tested it in my application by installing with

pip install git+git://github.com/defacto133/word_cloud.git@python3

and it seems to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.