I am trying to install the wordcloud library using 'pip install wordcloud' for a Data Science project, but the installation keeps failing. I'm getting a long error message about 'failed building wheel' and it mentions that it 'Microsoft Visual C++ 14.0 or greater is required.' I have Python installed on Windows 10, but I cannot get past this compiler error. What are the specific dependencies I am missing, and is there a way to install this without having to download a massive C++ build toolset?
3 answers
The error occurs because the wordcloud library contains C++ extensions that need to be compiled during the installation process. If your system lacks the necessary C++ compiler, pip fails to build the "wheel" for the package. To fix this, you have two main options. First, you can download the "Visual Studio Build Tools" from Microsoft's website and select the 'C++ build tools' workload. Alternatively, to avoid the large download, you can search for "Unofficial Windows Binaries for Python Extension Packages" and download the pre-compiled .whl file for wordcloud. Once downloaded, you can install it directly using pip install name_of_file.whl.
Are you using a virtual environment like venv or conda for this installation? Sometimes, using a Conda environment makes this much easier because it handles binary dependencies like C++ libraries more gracefully than standard pip does on Windows systems.
You should try updating your pip and setuptools first with python -m pip install --upgrade pip setuptools. Sometimes the newer versions of pip can find pre-built wheels more effectively.
I agree with Patricia. I've seen cases where simply upgrading setuptools allowed pip to recognize a compatible binary on PyPI, saving the user from having to manually install the 5GB Visual Studio build suite.
Christopher, that's an excellent suggestion for anyone working in Data Science. If you use the command conda install -c conda-forge wordcloud, it bypasses the need for the local C++ compiler entirely because Conda downloads a pre-compiled binary specifically for your environment. This is often the path of least resistance for beginners who are struggling with the 'Microsoft Visual C++ 14.0' error on Windows machines.