考纲
第三方库的获取和安装
脚本程序转变为可执行程序的第三方库:PyInstaller(必选)
第三方库:jieba库(必选)
第三方库:wordcloud库(可选)
C:\Users\asus>F:
F:\Python2\行文代码\第9章>PyInstaller -F SnowView.py
.
.
.
(错误)
F:\Python2\行文代码\第9章>PyInstaller -i snowflake.ico -F SnowView.py
>>> a="我是中国人我爱中国"
>>> import jieba
>>> jieba.lcut(a)
['我', '是', '中国', '人', '我', '爱', '中国']
>>> jieba.lcut("全国计算机等级考试")
['全国', '计算机', '等级', '考试']
>>> jieba.lcut("全国计算机等级考试",cut_all=True)
['全国', '国计', '计算', '计算机', '算机', '等级', '考试']
词云
from wordcloud import WordCloud
t="i like python i am learning python"
word=WordCloud().generate(t)
word.to_file("aaa.png")
字体文件夹 C:\Windows\Fonts
import jieba
from wordcloud import WordCloud
txt="程序将设计语言是计算机能够理解和识别用户操作意图的一种交互体系,它按照特定规划组织、计算机指令,使计算机能够自动进行各种运算处理。"
words=jieba.lcut(txt)
newtxt=" ".join(words)
wordcloud=WordCloud(font_path="msyh.ttc").generate(newtxt)
wordcloud.to_file("词云中文例子图.png")
pip install scipy
from wordcloud import WordCloud
from scipy.misc import imread
mask=imread("AliceMask.png")
f=open("AliceInWonderland.txt","r",ending="utf-8")
txt=f.read()
wordcloud=WordCloud(backgroud_color="white",\
width=800,\
height=600,\
max_words=200,\
max_font_size=80,\
mask=mask,\
).generate(txt)
wordcloud.to_file("AliceInWonderland.png")
PyInstaller
C:\Users\asus>F:
F:\Python2\行文代码\第9章>PyInstaller -F SnowView.py
.
.
.
(错误)
F:\Python2\行文代码\第9章>PyInstaller -i snowflake.ico -F SnowView.py
C:\Users\asus>pip download PyInstaller
Collecting PyInstaller
File was already downloaded c:\users\asus\PyInstaller-3.6.tar.gz
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting setuptools
File was already downloaded c:\users\asus\setuptools-45.2.0-py3-none-any.whl
Collecting pefile>=2017.8.1
File was already downloaded c:\users\asus\pefile-2019.4.18.tar.gz
Collecting altgraph
File was already downloaded c:\users\asus\altgraph-0.17-py2.py3-none-any.whl
Collecting pywin32-ctypes>=0.2.0
File was already downloaded c:\users\asus\pywin32_ctypes-0.2.0-py2.py3-none-any.whl
Collecting future
Downloading future-0.18.2.tar.gz (829 kB)
|████████████████████████████████| 829 kB 11 kB/s
Saved c:\users\asus\future-0.18.2.tar.gz
Successfully downloaded PyInstaller setuptools pefile altgraph pywin32-ctypes future
C:\Users\asus>pip install PyInstaller
Collecting PyInstaller
Using cached PyInstaller-3.6.tar.gz (3.5 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: pefile>=2017.8.1 in d:\python35\lib\site-packages (from PyInstaller) (2018.8.8)
Requirement already satisfied: setuptools in d:\python35\lib\site-packages (from PyInstaller) (28.8.0)
Collecting pywin32-ctypes>=0.2.0
Using cached pywin32_ctypes-0.2.0-py2.py3-none-any.whl (28 kB)
Collecting altgraph
Using cached altgraph-0.17-py2.py3-none-any.whl (21 kB)
Requirement already satisfied: future in d:\python35\lib\site-packages (from pefile>=2017.8.1->PyInstaller) (0.16.0)
Building wheels for collected packages: PyInstaller
Building wheel for PyInstaller (PEP 517) ... done
Created wheel for PyInstaller: filename=PyInstaller-3.6-py3-none-any.whl size=2926582 sha256=d2b88997d4ea077b1c865b11852ec71148da4f8eaf9474803526d5537ebde0f5
Stored in directory: c:\users\asus\appdata\local\pip\cache\wheels\dd\b6\1e\537449aa2dd036db5da60b14c61f136c5a9e16d79bd5491fc6
Successfully built PyInstaller
Installing collected packages: pywin32-ctypes, altgraph, PyInstaller
Successfully installed PyInstaller-3.6 altgraph-0.17 pywin32-ctypes-0.2.0
pip
Microsoft Windows [版本 10.0.17763.1039]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\asus>python
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello")
hello
>>> exit()
C:\Users\asus>pip install pygame
Collecting pygame
Downloading https://files.pythonhosted.org/packages/45/a5/580578790aa2f8f274855d45b4c89ffb910f1c72ddb754873b2ae8d7fc7f/pygame-1.9.6-cp35-cp35m-win_amd64.whl (4.3MB)
100% |████████████████████████████████| 4.3MB 13kB/s
Installing collected packages: pygame
Successfully installed pygame-1.9.6
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\asus>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
pygame (1.9.6)
setuptools (28.8.0)
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\asus>pip wordcloud
ERROR: unknown command "wordcloud"
C:\Users\asus>python --version
Python 3.5.3
C:\Users\asus>pip unistall wordcloud
ERROR: unknown command "unistall" - maybe you meant "uninstall"
C:\Users\asus>pip install wordcloud
Collecting wordcloud
Downloading https://files.pythonhosted.org/packages/d2/11/ebc51ff21ebc1a48b040859b0062bff4aa297c6cf26b1aa08a2c0ce22668/wordcloud-1.6.0-cp35-cp35m-win_amd64.whl (153kB)
100% |████████████████████████████████| 163kB 6.5kB/s
Collecting numpy>=1.6.1 (from wordcloud)
Could not find a version that satisfies the requirement numpy>=1.6.1 (from wordcloud) (from versions: )
No matching distribution found for numpy>=1.6.1 (from wordcloud)
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\asus>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
pygame (1.9.6)
setuptools (28.8.0)
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\asus>pip help
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should
attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
C:\Users\asus>