Python環境構築メモ

Python使っていて必要に応じていろんなライブラリを入れてしまったので、後々混乱しないようにメモしておきます。

Ptyhonにはいろんなインストール方法がありますが、すべての良し悪しを比較するような時間がないので、私はAnacondaをインストールしています。以下から64-Bit Graphical Installerをダウンロードしました。

https://www.anaconda.com/distribution/#download-section

この記事を書いたときのバージョンはPython 3.7です。

インストーラーに従ってインストールします。インストール先のフォルダは

C:\Users\riverlink\anaconda3

特にオプションなどは選択せずデフォルトのままインストールしました。

 

開発環境について

開発環境もいろんな選択肢があります。どれが良いのかはわかりませんが、現状Spyderを利用しています。先程ダウンロードしたイントーラーに同梱されていますのですぐに利用できます。

利用しているライブラリリスト

Anacondaをインストールするとnumpyやpandasなど超頻繁に利用するライブラリがデフォルトでインストールされます。しかしいろいろやっていると、追加でインストールしたほうが良いライブラリに遭遇します。

ここでは、これまで開発してきたプロジェクトで必要になったライブラリのリストをここに記述しておき、忘れても良い感じにしておきます。随時追記していくことにします。

ライブラリのインストールは”Anaconda Prompt(anaconda3)”から行います。基本的なインストールコマンドは以下です。

pip install [ライブラリ名]

conda install [ライブラリ名]


PySimpleGUI

https://pysimplegui.readthedocs.io/en/latest/

簡易なGUIシステムを作る上で非常に使いやすいライブラリです。以下でインストールします。

>pip install pysimplegui
Collecting pysimplegui
Downloading PySimpleGUI-4.16.0-py3-none-any.whl (306 kB)
|████████████████████████████████| 306 kB 3.3 MB/s
Installing collected packages: pysimplegui
Successfully installed pysimplegui-4.16.0


PyProj

https://pypi.org/project/pyproj/

いわずとしれた座標変換ツールです。地図の上に何か描画するようなアプリを作成する場合は必須のものです。以下でインストールします。

>pip install pyproj
Collecting pyproj
Downloading pyproj-2.5.0-cp37-cp37m-win_amd64.whl (24.0 MB)
|████████████████████████████████| 24.0 MB 2.2 MB/s
Installing collected packages: pyproj
Successfully installed pyproj-2.5.0


h5py

https://pypi.org/project/h5py/#description

これはiRICの計算条件や計算結果を格納しているCGNSファイルが利用しているHDF5形式への入出力用ライブラリです。以下でインストールできるのですが、ここでは既に入っていたようです。。。

>pip install h5py
Requirement already satisfied: h5py in c:\users\riverlink\anaconda3\lib\site-packages (2.10.0)
Requirement already satisfied: six in c:\users\riverlink\anaconda3\lib\site-packages (from h5py) (1.14.0)
Requirement already satisfied: numpy>=1.7 in c:\users\riverlink\anaconda3\lib\site-packages (from h5py) (1.18.1)


Plotly

https://plot.ly/python/

これは超強力なグラフツールです。Anacondaをインストールするとデフォルトでmatplotlibが入っており、matplotlibを利用してグラフを描くこともできますが、見栄えの良いグラフを描いたり、Web地図と連携させたり、HTML化したりなどなど非常に多くの機能があります。私はmatplotlibと併用してPlotolyを利用しています。以下でインストールします。

>pip install plotly==4.5.4
Collecting plotly==4.5.4
Downloading plotly-4.5.4-py2.py3-none-any.whl (7.1 MB)
|████████████████████████████████| 7.1 MB 6.4 MB/s
Requirement already satisfied: six in c:\users\riverlink\anaconda3\lib\site-packages (from plotly==4.5.4) (1.14.0)
Collecting retrying>=1.3.3
Downloading retrying-1.3.3.tar.gz (10 kB)
Building wheels for collected packages: retrying
Building wheel for retrying (setup.py) … done
Created wheel for retrying: filename=retrying-1.3.3-py3-none-any.whl size=11435 sha256=b2c2b6d53697bf2719cb79c25200af18d8b72a00cc1f0b5f8b7f0a41f41b3b88
Stored in directory: c:\users\riverlink\appdata\local\pip\cache\wheels\f9\8d\8d\f6af3f7f9eea3553bc2fe6d53e4b287dad18b06a861ac56ddf
Successfully built retrying
Installing collected packages: retrying, plotly
Successfully installed plotly-4.5.4 retrying-1.3.3


Node.js

https://nodejs.org/ja/

これはJavaScript環境なのですが、plotly で静的な画像を出力する際に必要になるライブラリcrcaやelectronをインストールするときに、npmコマンドを利用するためにインストールします。

上記にアクセスし、インストーラーをダウンロードしてインストールしてください。デフォルトでは以下にインストールされるようです。デフォルトの設定を変更せずにインストールしました。

C:\Program Files\nodejs\

インストールすると”Node.js command prompt”が利用できるようになります。node.js環境にパスが通ったコマンドプロンプトです。


electron@1.8.4 orca

https://github.com/plotly/orca

https://www.electronjs.org/

これはplotly で静的な画像を出力する際に必要になるライブラリです。plotlyと一緒に入れておきましょう。以下でインストールします。

>npm install -g electron@1.8.4 orca
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
C:\Users\riverlink\AppData\Roaming\npm\electron -> C:\Users\riverlink\AppData\Roaming\npm\node_modules\electron\cli.js
C:\Users\riverlink\AppData\Roaming\npm\orca -> C:\Users\riverlink\AppData\Roaming\npm\node_modules\orca\bin\orca.js

> electron@1.8.4 postinstall C:\Users\riverlink\AppData\Roaming\npm\node_modules\electron
> node install.js

Downloading SHASUMS256.txt
[============================================>] 100.0% of 3.43 kB (3.43 kB/s)
+ electron@1.8.4
+ orca@1.3.0
added 289 packages from 304 contributors in 41.671s

 


psutil

https://pypi.org/project/psutil/

これは(以下本家の説明をコピペしました。)

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoringprofiling and limiting process resources and management of running processes. It implements many functionalities offered by classic UNIX command line tools such as ps, top, iotop, lsof, netstat, ifconfig, free and others. psutil currently supports the following platforms:

だそうです。これがないとうまく動かないライブラリがあります。以下でインストールします。

>pip install plotly psutil
Requirement already satisfied: plotly in c:\users\riverlink\anaconda3\lib\site-packages (4.5.4)
Requirement already satisfied: psutil in c:\users\riverlink\anaconda3\lib\site-packages (5.6.7)
Requirement already satisfied: retrying>=1.3.3 in c:\users\riverlink\anaconda3\lib\site-packages (from plotly) (1.3.3)
Requirement already satisfied: six in c:\users\riverlink\anaconda3\lib\site-packages (from plotly) (1.14.0)


openpyxl

https://openpyxl.readthedocs.io/en/stable/

PythonからExcelを使うためのライブラリです。

以下でインストールします。

>pip install openpyxl
Requirement already satisfied: openpyxl in c:\users\riverlink\anaconda3\lib\site-packages (3.0.0)
Requirement already satisfied: jdcal in c:\users\riverlink\anaconda3\lib\site-packages (from openpyxl) (1.4.1)
Requirement already satisfied: et-xmlfile in c:\users\riverlink\anaconda3\lib\site-packages (from openpyxl) (1.0.1)


python-docx

https://python-docx.readthedocs.io/en/latest/user/install.html

PythonからWordファイルを使うためのライブラリです。

以下でインストールします。

>pip install python-docx
Collecting python-docx
Downloading python-docx-0.8.10.tar.gz (5.5 MB)
|████████████████████████████████| 5.5 MB 595 kB/s
Requirement already satisfied: lxml>=2.3.2 in c:\users\riverlink\anaconda3\lib\site-packages (from python-docx) (4.5.0)
Building wheels for collected packages: python-docx
Building wheel for python-docx (setup.py) … done
Created wheel for python-docx: filename=python_docx-0.8.10-py3-none-any.whl size=184495 sha256=35f6a42cb9d2ca1d3fa1159803bdc1140d3269767b446a4f1fe762d80d1d088a
Stored in directory: c:\users\riverlink\appdata\local\pip\cache\wheels\75\c6\69\05491f32dc052cd70476b65f5bf7082a9b274045f6b001b821
Successfully built python-docx
Installing collected packages: python-docx
Successfully installed python-docx-0.8.10


OpenCV

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html

Pythonで画像を扱うためのライブラリです。

以下でインストールします。

pip install opencv-python
Collecting opencv-python
Downloading opencv_python-4.2.0.32-cp37-cp37m-win_amd64.whl (33.0 MB)
|████████████████████████████████| 33.0 MB 819 kB/s
Requirement already satisfied: numpy>=1.14.5 in c:\users\riverlink\anaconda3\lib\site-packages (from opencv-python) (1.18.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.2.0.32


gdal

https://gdal.org/

Pythonでさまざまなフォーマットの地理空間データを扱うためのライブラリです

以下でインストールします。

>conda install -c conda-forge gdal
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
current version: 4.7.12
latest version: 4.8.2

Please update conda by running

$ conda update -n base -c defaults conda

## Package Plan ##

environment location: C:\Users\riverlink\Anaconda3

added / updated specs:
– gdal


The following packages will be downloaded:

package | build
—————————|—————–
boost-cpp-1.72.0 | h0caebb8_0 32.2 MB conda-forge
certifi-2019.9.11 | py37_0 147 KB conda-forge
conda-4.8.3 | py37hc8dfbb8_0 3.1 MB conda-forge
expat-2.2.9 | he025d50_2 116 KB conda-forge
freexl-1.0.5 | hd288d7e_1002 56 KB conda-forge
gdal-2.3.3 | py37hdf43c64_0 984 KB
geos-3.7.1 | h33f27b4_0 771 KB
hdf4-4.2.13 | h712560f_2 1.3 MB
kealib-1.4.7 | h07cbb95_6 133 KB
libgdal-2.3.3 | h10f50ba_0 7.2 MB
libkml-1.3.0 | h7e985d0_1011 54.6 MB conda-forge
libnetcdf-4.6.1 | h411e497_2 494 KB
libpq-11.2 | h3235a2c_0 2.6 MB
libspatialite-4.3.0a | h6a0152f_1026 4.3 MB conda-forge
pcre-8.44 | h6538335_0 492 KB conda-forge
proj4-5.2.0 | h6538335_1006 3.3 MB conda-forge
python_abi-3.7 | 1_cp37m 4 KB conda-forge
xerces-c-3.2.2 | h6538335_1004 4.0 MB conda-forge
————————————————————
Total: 115.8 MB

The following NEW packages will be INSTALLED:

boost-cpp conda-forge/win-64::boost-cpp-1.72.0-h0caebb8_0
expat conda-forge/win-64::expat-2.2.9-he025d50_2
freexl conda-forge/win-64::freexl-1.0.5-hd288d7e_1002
gdal pkgs/main/win-64::gdal-2.3.3-py37hdf43c64_0
geos pkgs/main/win-64::geos-3.7.1-h33f27b4_0
hdf4 pkgs/main/win-64::hdf4-4.2.13-h712560f_2
kealib pkgs/main/win-64::kealib-1.4.7-h07cbb95_6
libgdal pkgs/main/win-64::libgdal-2.3.3-h10f50ba_0
libkml conda-forge/win-64::libkml-1.3.0-h7e985d0_1011
libnetcdf pkgs/main/win-64::libnetcdf-4.6.1-h411e497_2
libpq pkgs/main/win-64::libpq-11.2-h3235a2c_0
libspatialite conda-forge/win-64::libspatialite-4.3.0a-h6a0152f_1026
pcre conda-forge/win-64::pcre-8.44-h6538335_0
proj4 conda-forge/win-64::proj4-5.2.0-h6538335_1006
python_abi conda-forge/win-64::python_abi-3.7-1_cp37m
xerces-c conda-forge/win-64::xerces-c-3.2.2-h6538335_1004

The following packages will be UPDATED:

conda pkgs/main::conda-4.7.12-py37_0 –> conda-forge::conda-4.8.3-py37hc8dfbb8_0

The following packages will be SUPERSEDED by a higher-priority channel:

certifi pkgs/main –> conda-forge


Proceed ([y]/n)? y


Downloading and Extracting Packages
freexl-1.0.5 | 56 KB | ############################################################################ | 100%
libnetcdf-4.6.1 | 494 KB | ############################################################################ | 100%
conda-4.8.3 | 3.1 MB | ############################################################################ | 100%
kealib-1.4.7 | 133 KB | ############################################################################ | 100%
proj4-5.2.0 | 3.3 MB | ############################################################################ | 100%
geos-3.7.1 | 771 KB | ############################################################################ | 100%
pcre-8.44 | 492 KB | ############################################################################ | 100%
libkml-1.3.0 | 54.6 MB | ############################################################################ | 100%
libpq-11.2 | 2.6 MB | ############################################################################ | 100%
python_abi-3.7 | 4 KB | ############################################################################ | 100%
boost-cpp-1.72.0 | 32.2 MB | ############################################################################ | 100%
gdal-2.3.3 | 984 KB | ############################################################################ | 100%
libspatialite-4.3.0a | 4.3 MB | ############################################################################ | 100%
certifi-2019.9.11 | 147 KB | ############################################################################ | 100%
hdf4-4.2.13 | 1.3 MB | ############################################################################ | 100%
expat-2.2.9 | 116 KB | ############################################################################ | 100%
xerces-c-3.2.2 | 4.0 MB | ############################################################################ | 100%
libgdal-2.3.3 | 7.2 MB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done


remi

RemiはPythonアプリケーション用のGUIライブラリで、アプリケーションのインタフェースをHTMLに変換してWebブラウザに表示します。 これにより、プラットフォーム固有の依存関係が削除され、Pythonでクロスプラットフォームアプリケーションを簡単に開発できます!

以下でインストールします。

>pip install remi
Collecting remi
Downloading https://files.pythonhosted.org/packages/08/6f/0b3e2087c813e2810c9c4ceaf941034d37bc3679faffad5a04d6fe0bcfd2/remi-2020.3.10-py3-none-any.whl (505kB)
|████████████████████████████████| 512kB 6.8MB/s
Installing collected packages: remi
Successfully installed remi-2020.3.10

このテキストを変更するには編集ボタンをクリックしてください。Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.