WinPython は,Window 用のPython 処理系と主要な Python パッケージを1つにまとめたソフトウェア.次のアプリケーションも同封されている
インストール,インストール後の設定,Python の各種パッケージのインストール,性能確認の手順をスクリーンショット等で説明する.
※
TensorFlow を使う予定がある場合は,https://pypi.org/project/tensorflow-gpu/#filesで,必要な Python のバージョンを確認しておく. 2022/9 時点では,TensorFlow バージョン 2.10 が動くのは,Python 3.10 または Python 3.9 または Python 3.8 または Python 3.7 (https://pypi.org/project/tensorflow/2.10/#files)
【目次】
※ ここでは最新の安定版であるバージョン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 ..
Windows では,コマンドプロン プトを管理者として実行し, 次のコマンドを実行する.
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)
実行結果の例
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow-intel tensorflow-text tf-models-official tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer
pip を用いてインストール
python -m pip install -U tensorflow==2.10.1 tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer python -m pip install git+https://github.com/tensorflow/docs python -m pip install git+https://github.com/tensorflow/examples.git python -m pip install git+https://www.github.com/keras-team/keras-contrib.git
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import numpy; print( numpy.__version__ )"
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import tensorflow as tf; print( tf.__version__ )"
このうち,多くのものは WinPython に同封されているのでインストールの必要はないが, WinPython に無いものは,次の操作でインストールする.
コマンドプロンプトを管理者として実行: 別ページ »で説明
sudo apt -y update sudo apt -y install libmecab-dev python -m pip install -U pip setuptools python -m pip install -U numpy scipy h5py scikit-learn scikit-learn-intelex 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 pyglet pygame cocos2d 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」で実行しているところ.
画像が表示される. 画像の画面を閉じるには,画像のウインドウでマウスをクリックし,キーボードのキーを押す.
ここで使用するビデオ: 1-1.avi (3分1秒)
動画ファイル c:/1-1.aviの 400 x 300 画素部分を表示する Python プログラム.
import cv2 v = cv2.VideoCapture("c:/1-1.avi") while(v.isOpened()): r, f = v.read() if ( r == False ): break f = f[0:400, 0:300, 0:3] cv2.imshow("", f) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
Windows で,コマンドプロンプトを開き,「python」で実行しているところ.
WinPython に付属の「spyder」で実行しているところ.