はじめに
ローカルパソコンにインストール可能なPythonの開発環境には次のようなものがあります。
- CPython(Pythonの基本パッケージ)
- Anaconda(CPython+数値計算ライブラリ+各種ツール)
- Miniconda(Anacondaから必要最小限のライブラリやツールを抜粋)
- Miniforge(Minicondaでdefaultリポジトリを削除してconda-forgeリポジトリを追加)
ここで、AnacondaとMinicondaは有償となる場合があります。そこで本記事では無償の環境構築を目的として、Minicondaと同じ操作で使える無償のMiniforgeを使ってPythonの開発環境を構築します。ライブラリはOpenCV、scikit-learn、Kerasなどが使えるようにします。
やり方
この記事では、64ビットのWindows11のパソコンにMiniforgeの開発環境を構築する手順を記します。TensorflowとKerasはバージョン2.10.0、OpenCVはバージョン4.5.1.48をインストールします。なお、ライブラリのインストール中にProceed ([y]/n)?
と聞かれたら、y "Enter"
で次に進めます。
-
Miniforgeのサイト
https://github.com/conda-forge/miniforge
の右側にある「conda-forge.org/download」をクリックします。
-
コマンドプロンプトが表示されます。
(base)は現在の開発環境(デフォルトの開発環境)を表します。
インストールされている環境を調べて、開発環境がbaseだけであることを確認しておきます。
conda info -e
-
Condaを最新のバージョンにアップデートします。
conda update conda
-
ここで、新規に「py38」という名前の仮想環境を構築します。
この環境で使用するPythonのバージョンは3.8とします。
conda create -n py38 python=3.8
-
環境の構築が終了したら、仮想環境「py38」に移行します。
conda activate py38
左端の表示が(base)から(py38)に変わります。
-
仮想環境「py38」に、よく使うライブラリをインストールします。
conda install numpy scipy sympy matplotlib scikit-learn pandas jupyter notebook ipykernel jupyterlab graphviz pydot
-
tensorflowの2.10をインストールします。
conda install tensorflow==2.10
インストールできないというメッセージが表示されるので、pipを使ってインストールします。
pip install tensorflow==2.10
これにより、Kerasもインストールされます。 -
opencv-pythonの4.5.0をインストールします。
conda install opencv-python==4.5.0
インストールできないというメッセージが表示されるため、pipを使ってインストールします。
pip install opencv-python==4.5.0
バージョンが見つからないというメッセージが表示されるため、それに近い4.5.1.48をインストールします。
pip install opencv-python==4.5.1.48
-
仮想環境の内容をファイルに書き出してみます。
conda env export > environment.yml
-------------------------------------------
environment.ymlを表示(折りたたみ)
---------------------------------------------
name: py38
channels:
- conda-forge
dependencies:
- anyio=4.5.0=pyhd8ed1ab_0
- argon2-cffi=23.1.0=pyhd8ed1ab_0
- argon2-cffi-bindings=21.2.0=py38h91455d4_4
- arrow=1.3.0=pyhd8ed1ab_0
- asttokens=3.0.0=pyhd8ed1ab_0
- async-lru=2.0.4=pyhd8ed1ab_0
- attrs=24.2.0=pyh71513ae_0
- babel=2.16.0=pyhd8ed1ab_0
- backcall=0.2.0=pyh9f0ad1d_0
- beautifulsoup4=4.12.3=pyha770c72_0
- bleach=6.1.0=pyhd8ed1ab_0
- brotli=1.1.0=h2466b09_2
- brotli-bin=1.1.0=h2466b09_2
- brotli-python=1.0.9=py38hd3f51b4_8
- bzip2=1.0.8=h2466b09_7
- ca-certificates=2025.1.31=h56e8100_0
- cached-property=1.5.2=hd8ed1ab_1
- cached_property=1.5.2=pyha770c72_1
- cairo=1.18.2=h5782bbf_1
- certifi=2024.8.30=pyhd8ed1ab_0
- cffi=1.17.0=py38h4cb3324_0
- charset-normalizer=3.4.0=pyhd8ed1ab_0
- colorama=0.4.6=pyhd8ed1ab_0
- comm=0.2.2=pyhd8ed1ab_0
- contourpy=1.1.1=py38hb1fd069_1
- cpython=3.8.20=py38hd8ed1ab_2
- cycler=0.12.1=pyhd8ed1ab_0
- debugpy=1.8.5=py38h2698bfa_0
- decorator=5.1.1=pyhd8ed1ab_0
- defusedxml=0.7.1=pyhd8ed1ab_0
- entrypoints=0.4=pyhd8ed1ab_0
- exceptiongroup=1.2.2=pyhd8ed1ab_0
- executing=2.1.0=pyhd8ed1ab_0
- font-ttf-dejavu-sans-mono=2.37=hab24e00_0
- font-ttf-inconsolata=3.000=h77eed37_0
- font-ttf-source-code-pro=2.038=h77eed37_0
- font-ttf-ubuntu=0.83=h77eed37_3
- fontconfig=2.15.0=h765892d_1
- fonts-conda-ecosystem=1=0
- fonts-conda-forge=1=0
- fonttools=4.53.1=py38h4cb3324_0
- fqdn=1.5.1=pyhd8ed1ab_0
- freetype=2.12.1=hdaf720e_2
- fribidi=1.0.10=h8d14728_0
- getopt-win32=0.1=hcfcfb64_1
- glib=2.82.2=h3d4babf_1
- glib-tools=2.82.2=h4394cf3_1
- graphite2=1.3.13=h63175ca_1003
- graphviz=12.2.1=hf40819d_1
- gst-plugins-base=1.24.7=hb0a98b8_0
- gstreamer=1.24.7=h5006eae_0
- gts=0.7.6=h6b5321d_4
- h11=0.14.0=pyhd8ed1ab_0
- h2=4.1.0=pyhd8ed1ab_0
- harfbuzz=10.3.0=h9e37d49_0
- hpack=4.0.0=pyh9f0ad1d_0
- httpcore=1.0.7=pyh29332c3_1
- httpx=0.27.2=pyhd8ed1ab_0
- hyperframe=6.0.1=pyhd8ed1ab_0
- icu=75.1=he0c23c2_0
- idna=3.10=pyhd8ed1ab_0
- importlib-metadata=8.5.0=pyha770c72_0
- importlib-resources=6.4.5=pyhd8ed1ab_0
- importlib_metadata=8.5.0=hd8ed1ab_1
- importlib_resources=6.4.5=pyhd8ed1ab_0
- intel-openmp=2024.2.1=h57928b3_1083
- ipykernel=6.29.5=pyh4bbf305_0
- ipython=8.12.2=pyh08f2357_0
- ipywidgets=8.1.5=pyhd8ed1ab_0
- isoduration=20.11.0=pyhd8ed1ab_0
- jedi=0.19.1=pyhd8ed1ab_0
- jinja2=3.1.4=pyhd8ed1ab_0
- joblib=1.4.2=pyhd8ed1ab_0
- json5=0.9.25=pyhd8ed1ab_0
- jsonpointer=3.0.0=py38haa244fe_0
- jsonschema=4.23.0=pyhd8ed1ab_0
- jsonschema-specifications=2024.10.1=pyhd8ed1ab_0
- jsonschema-with-format-nongpl=4.23.0=hd8ed1ab_1
- jupyter=1.1.1=pyhd8ed1ab_0
- jupyter-lsp=2.2.5=pyhd8ed1ab_0
- jupyter_client=8.6.3=pyhd8ed1ab_0
- jupyter_console=6.6.3=pyhd8ed1ab_0
- jupyter_core=5.7.2=pyh5737063_1
- jupyter_events=0.10.0=pyhd8ed1ab_0
- jupyter_server=2.14.2=pyhd8ed1ab_0
- jupyter_server_terminals=0.5.3=pyhd8ed1ab_0
- jupyterlab=4.2.5=pyhd8ed1ab_0
- jupyterlab_pygments=0.3.0=pyhd8ed1ab_1
- jupyterlab_server=2.27.3=pyhd8ed1ab_0
- jupyterlab_widgets=3.0.13=pyhd8ed1ab_0
- kiwisolver=1.4.5=py38hb1fd069_1
- krb5=1.21.3=hdf4eb48_0
- lcms2=2.17=hbcf6048_0
- lerc=4.0.0=h63175ca_0
- libblas=3.9.0=31_h641d27c_mkl
- libbrotlicommon=1.1.0=h2466b09_2
- libbrotlidec=1.1.0=h2466b09_2
- libbrotlienc=1.1.0=h2466b09_2
- libcblas=3.9.0=31_h5e41251_mkl
- libclang13=19.1.7=default_ha5278ca_1
- libdeflate=1.23=h9062f6e_0
- libexpat=2.6.4=he0c23c2_0
- libffi=3.4.6=h537db12_0
- libgd=2.3.3=h7208af6_11
- libglib=2.82.2=h7025463_1
- libhwloc=2.11.2=default_hc8275d1_1000
- libiconv=1.18=h135ad9c_1
- libintl=0.22.5=h5728263_3
- libintl-devel=0.22.5=h5728263_3
- libjpeg-turbo=3.0.0=hcfcfb64_1
- liblapack=3.9.0=31_h1aa476e_mkl
- liblzma=5.6.4=h2466b09_0
- liblzma-devel=5.6.4=h2466b09_0
- libogg=1.3.5=h2466b09_0
- libpng=1.6.47=had7236b_0
- libsodium=1.0.18=h8d14728_1
- libsqlite=3.49.1=h67fdade_1
- libtiff=4.7.0=h797046b_3
- libvorbis=1.3.7=h0e60522_0
- libwebp-base=1.5.0=h3b0e114_0
- libxcb=1.16=h013a479_1
- libxml2=2.13.6=he286e8c_0
- libzlib=1.3.1=h2466b09_2
- m2w64-gcc-libgfortran=5.3.0=6
- m2w64-gcc-libs=5.3.0=7
- m2w64-gcc-libs-core=5.3.0=7
- m2w64-gmp=6.1.0=2
- m2w64-libwinpthread-git=5.0.0.4634.697f757=2
- markupsafe=2.1.5=py38h91455d4_0
- matplotlib=3.7.3=py38haa244fe_0
- matplotlib-base=3.7.3=py38h2724991_0
- matplotlib-inline=0.1.7=pyhd8ed1ab_0
- mistune=3.0.2=pyhd8ed1ab_0
- mkl=2024.2.2=h66d3029_15
- mpmath=1.3.0=pyhd8ed1ab_0
- msys2-conda-epoch=20160418=1
- munkres=1.1.4=pyh9f0ad1d_0
- nbclient=0.10.2=pyhd8ed1ab_0
- nbconvert-core=7.16.4=pyhff2d567_2
- nbformat=5.10.4=pyhd8ed1ab_0
- nest-asyncio=1.6.0=pyhd8ed1ab_0
- notebook=7.2.2=pyhd8ed1ab_0
- notebook-shim=0.2.4=pyhd8ed1ab_0
- numpy=1.24.4=py38h1d91fd2_0
- openjpeg=2.5.3=h4d64b90_0
- openssl=3.4.1=ha4e3fda_0
- overrides=7.7.0=pyhd8ed1ab_0
- packaging=24.2=pyhd8ed1ab_2
- pandas=2.0.3=py38hf08cf0d_1
- pandocfilters=1.5.0=pyhd8ed1ab_0
- pango=1.56.1=h286b592_0
- parso=0.8.4=pyhd8ed1ab_0
- pcre2=10.44=h3d7b363_2
- pickleshare=0.7.5=py_1003
- pillow=10.4.0=py38h8d10685_0
- pip=24.3.1=pyh8b19718_0
- pixman=0.44.2=had0cd8c_0
- pkgutil-resolve-name=1.3.10=pyhd8ed1ab_1
- platformdirs=4.3.6=pyhd8ed1ab_0
- ply=3.11=pyhd8ed1ab_2
- pooch=1.8.2=pyhd8ed1ab_0
- prometheus_client=0.21.0=pyhd8ed1ab_0
- prompt-toolkit=3.0.48=pyha770c72_0
- prompt_toolkit=3.0.48=hd8ed1ab_1
- psutil=6.0.0=py38h4cb3324_0
- pthread-stubs=0.4=hcd874cb_1001
- pthreads-win32=2.9.1=h2466b09_4
- pure_eval=0.2.3=pyhd8ed1ab_0
- pycparser=2.22=pyhd8ed1ab_0
- pydot=3.0.1=py38haa244fe_0
- pygments=2.18.0=pyhd8ed1ab_0
- pyparsing=3.1.4=pyhd8ed1ab_0
- pyqt=5.15.9=py38hd6c051e_5
- pyqt5-sip=12.12.2=py38hd3f51b4_5
- pysocks=1.7.1=pyh0701188_6
- python=3.8.20=hfaddaf0_2_cpython
- python-dateutil=2.9.0=pyhd8ed1ab_0
- python-fastjsonschema=2.20.0=pyhd8ed1ab_0
- python-json-logger=2.0.7=pyhd8ed1ab_0
- python-tzdata=2024.2=pyhd8ed1ab_0
- python_abi=3.8=5_cp38
- pytz=2024.2=pyhd8ed1ab_0
- pywin32=306=py38hd3f51b4_2
- pywinpty=2.0.13=py38hd3f51b4_0
- pyyaml=6.0.2=py38h4cb3324_0
- pyzmq=26.2.0=py38h3c56b06_0
- qt-main=5.15.15=h9151539_2
- referencing=0.35.1=pyhd8ed1ab_0
- requests=2.32.3=pyhd8ed1ab_0
- rfc3339-validator=0.1.4=pyhd8ed1ab_0
- rfc3986-validator=0.1.1=pyh9f0ad1d_0
- rpds-py=0.20.0=py38h2e0ef18_0
- scikit-learn=1.3.2=py38h4f736e5_2
- scipy=1.10.1=py38h1aea9ed_3
- send2trash=1.8.3=pyh5737063_0
- setuptools=75.3.0=pyhd8ed1ab_0
- sip=6.7.12=py38hd3f51b4_0
- six=1.16.0=pyh6c4a22f_0
- sniffio=1.3.1=pyhd8ed1ab_0
- soupsieve=2.5=pyhd8ed1ab_1
- stack_data=0.6.2=pyhd8ed1ab_0
- sympy=1.13.3=pyh04b8f61_4
- tbb=2021.13.0=h62715c5_1
- terminado=0.18.1=pyh5737063_0
- threadpoolctl=3.5.0=pyhc1e730c_0
- tinycss2=1.4.0=pyhd8ed1ab_0
- tk=8.6.13=h5226925_1
- toml=0.10.2=pyhd8ed1ab_0
- tomli=2.0.2=pyhd8ed1ab_0
- tornado=6.4.1=py38h4cb3324_0
- traitlets=5.14.3=pyhd8ed1ab_0
- types-python-dateutil=2.9.0.20241003=pyhff2d567_0
- typing-extensions=4.12.2=hd8ed1ab_0
- typing_extensions=4.12.2=pyha770c72_0
- typing_utils=0.1.0=pyhd8ed1ab_0
- ucrt=10.0.22621.0=h57928b3_1
- unicodedata2=15.1.0=py38h91455d4_0
- uri-template=1.3.0=pyhd8ed1ab_0
- urllib3=2.2.3=pyhd8ed1ab_0
- vc=14.3=h5fd82a7_24
- vc14_runtime=14.42.34433=h6356254_24
- vs2015_runtime=14.42.34433=hfef2bbc_24
- wcwidth=0.2.13=pyhd8ed1ab_0
- webcolors=24.8.0=pyhd8ed1ab_0
- webencodings=0.5.1=pyhd8ed1ab_2
- websocket-client=1.8.0=pyhd8ed1ab_0
- wheel=0.45.1=pyhd8ed1ab_0
- widgetsnbextension=4.0.13=pyhd8ed1ab_0
- win_inet_pton=1.1.0=pyh7428d3b_7
- winpty=0.4.3=4
- xorg-kbproto=1.0.7=hcd874cb_1002
- xorg-libice=1.1.1=hcd874cb_0
- xorg-libsm=1.2.4=hcd874cb_0
- xorg-libx11=1.8.9=h0076a8d_1
- xorg-libxau=1.0.11=hcd874cb_0
- xorg-libxdmcp=1.1.3=hcd874cb_0
- xorg-libxext=1.3.4=hcd874cb_2
- xorg-libxpm=3.5.17=hcd874cb_0
- xorg-libxt=1.3.0=hcd874cb_1
- xorg-xextproto=7.3.0=hcd874cb_1003
- xorg-xproto=7.0.31=hcd874cb_1007
- xz=5.6.4=h208afaa_0
- xz-tools=5.6.4=h2466b09_0
- yaml=0.2.5=h8ffe710_2
- zeromq=4.3.5=he1f189c_4
- zipp=3.21.0=pyhd8ed1ab_0
- zstandard=0.19.0=py38h91455d4_0
- zstd=1.5.7=hbeecb71_1
- pip:
- absl-py==2.1.0
- astunparse==1.6.3
- cachetools==5.5.2
- flatbuffers==25.2.10
- gast==0.4.0
- google-auth==2.38.0
- google-auth-oauthlib==0.4.6
- google-pasta==0.2.0
- grpcio==1.70.0
- h5py==3.11.0
- keras==2.10.0
- keras-preprocessing==1.1.2
- libclang==18.1.1
- markdown==3.7
- oauthlib==3.2.2
- opencv-python==4.5.1.48
- opt-einsum==3.4.0
- protobuf==3.19.6
- pyasn1==0.6.1
- pyasn1-modules==0.4.1
- requests-oauthlib==2.0.0
- rsa==4.9
- tensorboard==2.10.1
- tensorboard-data-server==0.6.1
- tensorboard-plugin-wit==1.8.1
- tensorflow==2.10.0
- tensorflow-estimator==2.10.0
- tensorflow-io-gcs-filesystem==0.31.0
- termcolor==2.4.0
- werkzeug==3.0.6
- wrapt==1.17.2
※最後の行(prefix: C:\Users\****\miniforge3\envs\****
などと書かれた内容)は削除しています。
なお、environment.ymlをMiniforgeがインストールされているパソコンにコピーして
conda env create -f environment.yml
を実行すれば、本記事と同じ環境を構築できます。
参考記事