From the completion of CentOS installation to the generation of word cloud python instance, centospython

Source: Internet
Author: User

From the completion of CentOS installation to the generation of word cloud python instance, centospython

Preface

My life is short. I use python. How can I skip word cloud when learning python?

So I got the notes recorded while practicing.

Environment: VMware 12pro + CentOS7 + Python 2.7.5

Install the system

We have been using the win10 subsystem before. Now try CentOS. download the latest system dvd version on the CentOS official website to install it on VMware 12pro. There are many tutorials online. For example, this link. Wait until the installation is complete.

First Command

If you do not have any command when using Ubuntu, you will be prompted to install it, which is very simple. However, it becomes a headache on CentOS.

When you open the terminal and run the following command to install python-pip.

Sudo yum install python-pip has no available software package python-pip.

Google said that this package is in the EPEL source. You only need to add the EPEL source.

Run the following two commands to install the SDK.

yum install epel-release.noarchyum install python-pip

Python library Installation

Next, install wordcloud.

Pip install-I https://pypi.tuna.tsinghua.edu.cn/simple wordcloud truncate partial error message unable to execute gcc: No such file or directoryerror: command 'gcc 'failed with exit status 1 does not even connect to gcc. Install gccyum install gcc first

After gcc is installed, continue to install wordcloud! The following error is reported again.

_ Posixsubprocess. c: 3: 20: Fatal error: Python. h: No file or directory. Therefore, you must first install python-develsudo yum install python-devel # note that this is not python-dev

CentOS is called python-devel and Ubuntu is also called python-dev.

Wordcloud has been installed!

Code

Generate a word cloud code and search for an English copy (Recruiters starting to employ social media I found in ChinaDaily is put in txt/word.txt

#-*-Coding: UTF-8-*-import matplotlib # Force matplotlib to not use any Xwindows backend. # matplotlib. use ('authorization') from wordcloud import WordCloudtextfile = open (u'txt/word.txt ', 'R '). read () wordcloud = WordCloud (background_color = "white", width = 800, height = 600, margin = 5 ). generate (textfile) # width, height, and margin can be used to set image attributes # generate comment ')

Run python clouddemo. py to report an error.

SyntaxError: Non-ASCII character '\xe5' in file clouddemo.py on line 6, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

The reason is as follows:

Python is encoded in ASCII by default. If the Python source code contains Chinese (or other non-English languages), even if you save your own Python source file in UTF-8 format, but in fact, this still does not work.

SolutionIt is very easy to add the following code at the beginning of the file; specify the file encoding format as UTF-8. I have added the above Code (. Else 'ω 'Then '.).

# -*- coding: UTF-8 -*- 

Encoding problem solved. Then run the command again.

An error is returned !!!

ImportError: No module named Tkinter

First, yum list installed | grep ^ tk

Check whether the corresponding module exists. If not, use yum install tkinter and yum install-y tk-devel to download the corresponding module.

The next error is prompted when you execute the command again.

tkinter.TclError: no display name and no $DISPLAY environment variable

Although a wave of N folds, but finally succeeded !!! Look at the word cloud under the source code directory!

As follows:

The above example, from the installation of CentOS to the generation of word cloud python, is all the content shared by Alibaba Cloud. I hope to give you a reference and support for the help house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.