WinPython は,Window 用のPython 処理系と主要な Python パッケージを1つにまとめたソフトウエア.次のアプリケーションも同封されている
インストール,インストール後の設定,Python の各種パッケージのインストール,性能確認の手順をスクリーンショット等で説明する.
※
TensorFlow を使う予定がある場合は,https://pypi.org/project/tensorflow-gpu/#filesで,必要な Python のバージョンを確認しておくこと. 2020/12 時点では,Python 3.6 か 3.7 か 3.8
【このページの目次】
※ ここでは最新の安定版であるバージョン3.7 を選んでいる.
「Download Latest Version」をクリック.
「C:\」のような分かりやすいディレクトリを指定.
指定したら,「Extract」をクリック.
終了するまでしばらく待つ.
C:\WPy64-3770\python-3.7.7.amd64 C:\WPy64-3770 C:\WPy64-3770\python-3.7.7.amd64\Scripts C:\WPy64-3770\Scripts
次のコマンドを実行
where pip where python
※ 表示は下図と違うことがありえる.エラーメッセージが出ないことを確認.
※ エラーメッセージが出ないことを確認.
python --version
python
下の実行例では、バージョン番号として「1900」が表示されている
下の実行例では、バージョン番号として「14.0」が表示されている
from distutils.msvc9compiler import * get_build_version()
exit() で終了
Python のパッケージも同時にインストールされることが分かる.
※ エラーメッセージが出ないことを確認.
pip list
WinPython で,numpy の更新により numpy が動かなくなることを防ぐため.
cd C:\WPy64-3770\python-3.7.7.amd64\Lib\site-packages move numpy ..
コマンドプロンプトを管理者として実行し,次のコマンドを実行.
python -m pip install -U pip setuptools
pip list
行列の積, 主成分分析, SVD, k-Means クラスタリングを実行し,性能を確認する.
import time import numpy import numpy.linalg import sklearn.decomposition import sklearn.cluster X = numpy.random.rand(2000, 2000) Y = numpy.random.rand(2000, 2000) # 行列の積 a = time.time(); Z = numpy.dot(X, Y); print(time.time() - a) # 主成分分析 pca = sklearn.decomposition.PCA(n_components = 2) a = time.time(); pca.fit(X); X_pca = pca.transform(X); print(time.time() - a) # SVD a = time.time(); U, S, V = numpy.linalg.svd(X); print(time.time() - a) # k-means a = time.time(); kmeans_model = sklearn.cluster.KMeans(n_clusters=10, random_state=10).fit(X) labels = kmeans_model.labels_ print(time.time() - a)
実行結果の例
GPU とは,グラフィックス・プロセッシング・ユニットの略で、コンピュータグラフィックス関連の機能,乗算や加算の並列処理の機能などがある.
NVIDIA CUDA は,NVIDIA社が提供している GPU 用のプラットフォームである.
関連 Web ページ
インストール手順の説明
Windows での NVIDIA グラフィックスドライバ,NVIDIA CUDA ツールキット 11.0のインストール: のインストール: 別ページで説明している.
ダウンロードページ
ダウンロードして展開(解凍)したら,パスを通しておくこと.
TensorFlow 2.4 の GPU 版での,cuDNN のバージョンは 8.0.5(現時点で,NVIDIA CUDA ツールキット 11 で動く最新版).
TensorFlow 2.3, 2.2, 2.1 の GPU 版での,cuDNN のバージョンは 7.6.そして,TensorFlow 1.13 以上 TensorFlow 2.0 までの GPU 版での,cuDNN のバージョンは7.4 .それより高いバージョンよりは使わないこと.
詳細説明
python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow_datasets tensorflow-hub keras
python -m pip install -U tensorflow tensorflow_datasets tensorflow-hub keras matplotlib opencv-python python -m pip install -q git+https://github.com/tensorflow/docs python -m pip install -q git+https://github.com/tensorflow/examples.git
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import numpy; print( numpy.__version__ )"
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import tensorflow as tf; print( tf.__version__ )"
このうち,多くのものは WinPython に同封されているのでインストールの必要はないが, WinPython に無いものは,次の操作でインストールする.
sudo apt -y install libmecab-dev python -m pip install -U pip setuptools python -m pip install -U numpy scipy h5py scikit-learn scikit-image seaborn pandas pillow pytest cython bokeh statsmodels plotly sympy csvkit docopt pyproj flake8 protobuf bs4 html5lib rope wrapt cffi wheel six sphinx bottleneck pygments numexpr xlrd xlsxwriter lxml graphviz pydot flask django redis pylint bz2file PyOpenGL msgpack mecab ggplot matplotlib-venn pygame bottle rtree shapely fiona geopandas geopy geographiclib requests \ pandasql pyyaml bokeh pymc3 mkl mkl-include holoviews pandas-bokeh ggplot prettyplotlib pybrain3 firebase-admin googletrans google-cloud-vision gpyocr azure-cognitiveservices-vision-computervision gensim gloo scikit-video scikits.datasmooth scikits.example scikits.fitting scikits.optimization scikits.vectorplot zodb gdata pyr2 pycaret python -m pip install -U gdal
OpenCV は有名なコンピュータビジョンのライブラリ
OpenCV の機能を使って,画像表示してみる.
OpenCV の機能とプログラム例は,別ページにまとめている.
画像ファイル c:/fruits.jpg を表示する Python プログラム.
import cv2
img = cv2.imread("c:/fruits.jpg")
cv2.imshow("hoge", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Windows で,コマンドプロンプトを実行し,「python」で実行しているところ.
WinPython に付属の「spyder」で実行しているところ.
画像が表示される. 画像の画面を閉じるには,画像のウインドウでマウスをクリックし,キーボードのキーを押す.
ビデオファイル c:/1-1.aviの 400 x 300 画素部分を表示する Python プログラム.
import cv2
v = cv2.VideoCapture("c:/1-1.avi")
while(v.isOpened()):
r, f = v.read()
f = f[0:400, 0:300, 0:3]
cv2.imshow("", f)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
v.release()
cv2.destroyAllWindows()
Windows で,コマンドプロンプトを実行し,「python」で実行しているところ.
WinPython に付属の「spyder」で実行しているところ.