戻る

AnacondaをWindowsにインストールする

Pythonのデータマイニング用ライブラリパッケージとして今回はAnacondaを使用する。

Anacondaは以下のサイトからダウンロードできる。
Download Anaconda Now

Anaconda 4.3.1 For Windows
Python 3.6 version

「64-Bit Installer (422M)」ボタンをクリックして、インストールファイルをダウンロードする。

ダウンロードした「Anaconda3-4.3.1-Windows-x86_64.exe」を実行する。

install1

install2

install3

install4

install5
インストールが開始されるので待機する。

install6
インストールは10分ほどで完了する。

install7

スタートメニューの「Anaconda3(64-bit)」から「Anaconda Prompt」を実行する。
install8
正常にインストールされていることが確認できたのでコマンドプロンプトを閉じる。

Tkinterを使ったサンプルGUIアプリを作成する

事前準備

Dドライブ直下に「python」フォルダーを作成する。
コマンドプロンプトのショートカットをD:\pythonに作成する。
作成したショートカットを右クリックし、コマンドプロンプトのプロパティで作業フォルダーを「D:\python」にする。

Tkinterの動作確認

TkinterはPythonに含まれているのでインストール不要。
コマンドプロンプトで以下のコマンドを実行する。
D:\python>python -m tkinter

install9
Tkinterが正常に動作していることが確認できたので、「QUIT」ボタンをクリックしてウィンドウを閉じる。

サンプルGUIアプリの作成

以下のソースコードをファイル名「ui.py」でD:\pythonに保存する。
import tkinter as tk
root = tk.Tk()
root.title(u'タイトル')
root.geometry('640x480')
tk.Label(text='サンプル').pack()
root.mainloop()

サンプルGUIアプリの実行

コマンドプロンプトで以下のコマンドを実行する。
D:\python>python ui.py

install10
正常にサンプルGUIアプリが表示されたので、右上の×ボタンでウィンドウを閉じる。

サンプルGUIアプリをexeファイルにする

pyinstallerをインストールする

コマンドプロンプトで以下のコマンドを実行する。
D:\python>conda create -n pyinstaller_test python setuptools=19.2 sympy pywin32

Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment C:\Users\user\Anaconda3\envs\pyinstaller_test:

The following NEW packages will be INSTALLED:

mpmath: 0.19-py35_1
pip: 9.0.1-py35_1
python: 3.5.3-0
pywin32: 220-py35_2
setuptools: 19.2-py35_0
sympy: 1.0-py35_0
vs2015_runtime: 14.0.25123-0
wheel: 0.29.0-py35_0

Proceed ([y]/n)?

yを入力して続行する。

python-3.5.3-0 100% |###############################| Time: 0:00:08 3.59 MB/s
mpmath-0.19-py 100% |###############################| Time: 0:00:00 2.31 MB/s
pywin32-220-py 100% |###############################| Time: 0:00:04 2.59 MB/s
setuptools-19. 100% |###############################| Time: 0:00:00 2.72 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00 3.02 MB/s
pip-9.0.1-py35 100% |###############################| Time: 0:00:00 2.67 MB/s
sympy-1.0-py35 100% |###############################| Time: 0:00:02 2.72 MB/s
#
# To activate this environment, use:
# > activate pyinstaller_test
#
# To deactivate this environment, use:
# > deactivate pyinstaller_test
#
# * for power-users using bash, you must source
#

以下のコマンドを実行する。
D:\python>activate pyinstaller_test

以下のコマンドを実行する。
(pyinstaller_test) D:\python>pip install pyinstaller

Collecting pyinstaller
Downloading PyInstaller-3.2.1.tar.bz2 (2.4MB)
100% |################################| 2.4MB 506kB/s
Requirement already satisfied: setuptools in c:\users\user\anaconda3\envs\pyinstaller_test\lib\site-packages\setuptools-19.2-py3.5.egg (from pyinstaller)
Collecting future (from pyinstaller)
Downloading future-0.16.0.tar.gz (824kB)
100% |################################| 829kB 1.3MB/s
Building wheels for collected packages: pyinstaller, future
Running setup.py bdist_wheel for pyinstaller ... done
Stored in directory: C:\Users\user\AppData\Local\pip\Cache\wheels\0b\d9\68\d6ac226a577f9a16459d486c5fe1a71cdc5846dd6515a13b0f
Running setup.py bdist_wheel for future ... done
Stored in directory: C:\Users\user\AppData\Local\pip\Cache\wheels\c2\50\7c\0d83b4baac4f63ff7a765bd16390d2ab43c93587fac9d6017a
Successfully built pyinstaller future
Installing collected packages: future, pyinstaller
Successfully installed future-0.16.0 pyinstaller-3.2.1

exeファイルを作成する

以下のコマンドを実行する。
(pyinstaller_test) D:\python>pyinstaller ui.py --onefile --noconsole

137 INFO: PyInstaller: 3.2.1
137 INFO: Python: 3.5.3
138 INFO: Platform: Windows-10-10.0.14393-SP0
142 INFO: wrote D:\python\ui.spec
144 INFO: UPX is not available.
146 INFO: Extending PYTHONPATH with paths
['D:\\python', 'D:\\python']
147 INFO: checking Analysis
147 INFO: Building Analysis because out00-Analysis.toc is non existent
147 INFO: Initializing module dependency graph...
153 INFO: Initializing module graph hooks...
155 INFO: Analyzing base_library.zip ...
2502 INFO: running Analysis out00-Analysis.toc
2529 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\user\anaconda3\envs\pyinstaller_test\python.exe
3093 INFO: Caching module hooks...
3100 INFO: Analyzing D:\python\ui.py
3195 INFO: Loading module hooks...
3195 INFO: Loading module hook "hook-pydoc.py"...
3197 INFO: Loading module hook "hook-_tkinter.py"...
3333 INFO: checking Tree
3333 INFO: Building Tree because out00-Tree.toc is non existent
3333 INFO: Building Tree out00-Tree.toc
3428 INFO: checking Tree
3429 INFO: Building Tree because out01-Tree.toc is non existent
3429 INFO: Building Tree out01-Tree.toc
3447 INFO: Loading module hook "hook-xml.py"...
3633 INFO: Loading module hook "hook-encodings.py"...
3756 INFO: Looking for ctypes DLLs
3756 INFO: Analyzing run-time hooks ...
3761 INFO: Including run-time hook 'pyi_rth__tkinter.py'
3767 INFO: Looking for dynamic libraries
4034 INFO: Looking for eggs
4034 INFO: Using Python library c:\users\user\anaconda3\envs\pyinstaller_test\python35.dll
4036 INFO: Found binding redirects:
[]
4042 INFO: Warnings written to D:\python\build\ui\warnui.txt
4130 INFO: checking PYZ
4131 INFO: Building PYZ because out00-PYZ.toc is non existent
4131 INFO: Building PYZ (ZlibArchive) D:\python\build\ui\out00-PYZ.pyz
4811 INFO: Building PYZ (ZlibArchive) D:\python\build\ui\out00-PYZ.pyz completed successfully.
4827 INFO: checking PKG
4827 INFO: Building PKG because out00-PKG.toc is non existent
4828 INFO: Building PKG (CArchive) out00-PKG.pkg
9149 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
9225 INFO: Bootloader c:\users\user\anaconda3\envs\pyinstaller_test\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
9225 INFO: checking EXE
9226 INFO: Building EXE because out00-EXE.toc is non existent
9226 INFO: Building EXE from out00-EXE.toc
9227 INFO: Appending archive to EXE D:\python\dist\ui.exe
9313 INFO: Building EXE from out00-EXE.toc completed successfully.

以下のフォルダーとファイルが生成される。
+__pycache__
--ui.cpython-35.pyc
+build
++ui
---base_library.zip
---out00-Analysis.toc
---out00-EXE.toc
---out00-PKG.pkg
---out00-PKG.toc
---out00-PYZ.pyz
---out00-PYZ.toc
---out00-Tree.toc
---out01-Tree.toc
---ui.exe.manifest
---warnui.txt
+dist
--ui.exe
-ui.spec

exeファイルを実行する

D:\python\distに作成された「ui.exe」を実行する。

install10
正常にサンプルGUIアプリが表示されたので、右上の×ボタンでウィンドウを閉じる。

戻る