pythonメニュー

pythonの構築環境

環境変数の取得

import os
os.os.environ[環境変数名の文字列]で、設定値が取得できる。

Anaconda をインストールした環境

virtualenvを利用
Anaconda の可能環境

conda deactivate この仮想環境を非 Active にして元の環境に戻る。
conda info 現在の仮想環境の情報表示
conda remove -n myenv --all 「myenv」の仮想環境の完全な削除
conda info -e 作成してある仮想環境の名前とディレクトリパスをリストアップ
Anaconda Navigaterを使っている場合、「Enviroments」からコマンドプロンプトを出して、 tensorflowの環境を作ってインストールした時の実行画面を示す。
C:\Users\yuu.PC7>conda create -n tensorflow pip python=3.5
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.4.10
  latest version: 4.5.0

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: C:\Users\yuu.PC7\Anaconda3\envs\tensorflow

  added / updated specs:
    - pip
    - python=3.5


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2018.1.18          |           py35_0         144 KB
    python-3.5.5               |       h0c2934d_1        18.6 MB
    wincertstore-0.2           |   py35hfebbdb8_0          13 KB
    setuptools-38.5.1          |           py35_0         548 KB
    wheel-0.30.0               |   py35h38a90bc_1          85 KB
    pip-9.0.1                  |           py35_5         2.6 MB
    ------------------------------------------------------------
                                           Total:        21.9 MB

The following NEW packages will be INSTALLED:

    certifi:        2018.1.18-py35_0
    pip:            9.0.1-py35_5
    python:         3.5.5-h0c2934d_1
    setuptools:     38.5.1-py35_0
    vc:             14-h0510ff6_3
    vs2015_runtime: 14.0.25123-3
    wheel:          0.30.0-py35h38a90bc_1
    wincertstore:   0.2-py35hfebbdb8_0

Proceed ([y]/n)? y


Downloading and Extracting Packages
certifi 2018.1.18: ############################################################################################################################################## | 100%
python 3.5.5: ################################################################################################################################################### | 100%
wincertstore 0.2: ############################################################################################################################################### | 100%
setuptools 38.5.1: ############################################################################################################################################## | 100%
wheel 0.30.0: ################################################################################################################################################### | 100%
pip 9.0.1: ###################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > activate tensorflow
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#


C:\Users\yuu.PC7>

C:\Users\yuu.PC7>activate tensorflow

(tensorflow) C:\Users\yuu.PC7>pip install --ignore-installed --upgrade tensorflow
Collecting tensorflow
  Downloading tensorflow-1.6.0-cp35-cp35m-win_amd64.whl (32.3MB)
    100% |################################| 32.3MB 547kB/s
Collecting gast>=0.2.0 (from tensorflow)
  Downloading gast-0.2.0.tar.gz
Collecting protobuf>=3.4.0 (from tensorflow)
  Downloading protobuf-3.5.2.post1-cp35-cp35m-win_amd64.whl (958kB)
    100% |################################| 962kB 5.4MB/s
Collecting wheel>=0.26 (from tensorflow)
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    100% |################################| 51kB 3.9MB/s
Collecting tensorboard<1.7.0,>=1.6.0 (from tensorflow)
  Downloading tensorboard-1.6.0-py3-none-any.whl (3.0MB)
    100% |################################| 3.1MB 2.3MB/s
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading termcolor-1.1.0.tar.gz
Collecting six>=1.10.0 (from tensorflow)
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting absl-py>=0.1.6 (from tensorflow)
  Downloading absl-py-0.1.12.tar.gz (79kB)
    100% |################################| 81kB 4.6MB/s
Collecting grpcio>=1.8.6 (from tensorflow)
  Downloading grpcio-1.10.0-cp35-cp35m-win_amd64.whl (1.3MB)
    100% |################################| 1.3MB 2.6MB/s
Collecting astor>=0.6.0 (from tensorflow)
  Downloading astor-0.6.2-py2.py3-none-any.whl
Collecting numpy>=1.13.3 (from tensorflow)
  Downloading numpy-1.14.2-cp35-none-win_amd64.whl (13.4MB)
    100% |################################| 13.4MB 1.5MB/s
Collecting setuptools (from protobuf>=3.4.0->tensorflow)
  Downloading setuptools-39.0.1-py2.py3-none-any.whl (569kB)
    100% |################################| 573kB 6.0MB/s
Collecting html5lib==0.9999999 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading html5lib-0.9999999.tar.gz (889kB)
    100% |################################| 890kB 5.4MB/s
Collecting bleach==1.5.0 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
    100% |################################| 327kB 2.6MB/s
Collecting markdown>=2.6.8 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading Markdown-2.6.11-py2.py3-none-any.whl (78kB)
    100% |################################| 81kB 4.6MB/s
Building wheels for collected packages: gast, termcolor, absl-py, html5lib
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\8e\fa\d6\77dd17d18ea23fd7b860e02623d27c1be451521af40dd4a13e
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\de\f7\bf\1bcac7bf30549e6a4957382e2ecab04c88e513117207067b03
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\d6\d5\fc\8405dfaa90e82a8665116b5058e14891c37b4a0a707e03b634
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\6f\85\6c\56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
Successfully built gast termcolor absl-py html5lib
Installing collected packages: gast, six, setuptools, protobuf, wheel, numpy, html5lib, bleach, werkzeug, markdown, tensorboard, termcolor, absl-py, grpcio, astor, tensorflow
Successfully installed absl-py-0.1.12 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-1.10.0 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.2 protobuf-3.5.2.post1 setuptools-39.0.1 six-1.11.0 tensorboard-1.6.0 tensorflow-1.6.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.30.0

(tensorflow) C:\Users\yuu.PC7>

(tensorflow) C:\Users\yuu.PC7>pip install keras==2.0.5
Collecting keras==2.0.5
  Downloading Keras-2.0.5.tar.gz (216kB)
    100% |################################| 225kB 5.0MB/s
Collecting theano (from keras==2.0.5)
  Downloading Theano-1.0.1.tar.gz (2.8MB)
    100% |################################| 2.8MB 4.3MB/s
Collecting pyyaml (from keras==2.0.5)
  Downloading PyYAML-3.12-cp35-cp35m-win_amd64.whl (195kB)
    100% |################################| 204kB 6.0MB/s
Requirement already satisfied: six in c:\users\yuu.pc7\anaconda3\envs\tensorflow\lib\site-packages (from keras==2.0.5)
Requirement already satisfied: numpy>=1.9.1 in c:\users\yuu.pc7\anaconda3\envs\tensorflow\lib\site-packages (from theano->keras==2.0.5)
Collecting scipy>=0.14 (from theano->keras==2.0.5)
  Downloading scipy-1.0.1-cp35-none-win_amd64.whl (30.8MB)
    100% |################################| 30.8MB 497kB/s
Building wheels for collected packages: keras, theano
  Running setup.py bdist_wheel for keras ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\f9\8d\c5\efc2eeea676156ca5bed9cfbdb63098c40336d7d2b269be5ea
  Running setup.py bdist_wheel for theano ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\46\a2\7d\b4cac381d5151daa9f9e0b3e4e4b65edaea6355ae296c97cf2
Successfully built keras theano
Installing collected packages: scipy, theano, pyyaml, keras
Successfully installed keras-2.0.5 pyyaml-3.12 scipy-1.0.1 theano-1.0.1

(tensorflow) C:\Users\yuu.PC7>

(tensorflow) C:\Users\yuu.PC7>pip install h5py
Collecting h5py
  Downloading h5py-2.7.1-cp35-cp35m-win_amd64.whl (2.2MB)
    100% |################################| 2.3MB 5.4MB/s
Requirement already satisfied: numpy>=1.7 in c:\users\yuu.pc7\anaconda3\envs\tensorflow\lib\site-packages (from h5py)
Requirement already satisfied: six in c:\users\yuu.pc7\anaconda3\envs\tensorflow\lib\site-packages (from h5py)
Installing collected packages: h5py
Successfully installed h5py-2.7.1
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(tensorflow) C:\Users\yuu.PC7>
最後にインストールいている「h5py」は、 HDF5「HDF(:Hierarchical Data Format)5形式を使うためのパッケージです。
これは階層化されたデータ"群"を取り扱うファイル形式で、 「フォルダ+データファイル」をひとまとめにできます。
複数の種類のデータ・ファイルをディレクトリを伴ってまとめたファイルで、圧縮はしませんが、そのままHDFviewerなどを使って編集ができます。
HDFviewerは、「https://support.hdfgroup.org/products/java/release/download.html」からWindowsであれば次のファイルがダウンロードできる。
「HDFView-2.14-win_64.zip」、「HDFJava-3.3.2_Stat-win7_64-vs14.zip」


なお、アップデートを勧めるメッセージが出ているので次のようにアップデートした。

(tensorflow) C:\Users\yuu.PC7>python -m pip install --upgrade pip
Collecting pip
  Downloading pip-9.0.3-py2.py3-none-any.whl (1.4MB)
    100% |################################| 1.4MB 6.0MB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-9.0.3

(tensorflow) C:\Users\yuu.PC7>

tensorflowのインストール

Python 3.6.6の環境にインストールする。
(tensorflowはバージョン1.6から、AVX(Advanced Vector Extensions)をサポートしていないCPUでは、単純なインストールがきなくなった?)
下記では、バージョン1.5を指定してインストールしている。
(my2) C:\Users\yuu.PC7>pip install --upgrade tensorflow==1.5.0
Collecting tensorflow==1.5.0
  Downloading https://files.pythonhosted.org/packages/34/96/11f048eca7b4d6da3084ca49c636b9e720e9dd1483c0c4e9ba3cf5037564/tensorflow-1.5.0-cp36-cp36m-win_amd64.whl (31.1MB)
    100% |????????????????????????????????| 31.1MB 600kB/s
Requirement already satisfied, skipping upgrade: numpy>=1.12.1 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow==1.5.0) (1.14.5)
Requirement already satisfied, skipping upgrade: absl-py>=0.1.6 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow==1.5.0) (0.6.1)
Requirement already satisfied, skipping upgrade: protobuf>=3.4.0 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow==1.5.0) (3.6.1)
Collecting tensorflow-tensorboard<1.6.0,>=1.5.0 (from tensorflow==1.5.0)
  Downloading https://files.pythonhosted.org/packages/cc/fa/91c06952517b4f1bc075545b062a4112e30cebe558a6b962816cb33efa27/tensorflow_tensorboard-1.5.1-py3-none-any.whl (3.0MB)
    100% |????????????????????????????????| 3.0MB 2.8MB/s
Requirement already satisfied, skipping upgrade: wheel>=0.26 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow==1.5.0) (0.32.2)
Requirement already satisfied, skipping upgrade: six>=1.10.0 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow==1.5.0) (1.11.0)
Requirement already satisfied, skipping upgrade: setuptools in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from protobuf>=3.4.0->tensorflow==1.5.0) (39.1.0)
Collecting bleach==1.5.0 (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5.0)
  Using cached https://files.pythonhosted.org/packages/33/70/86c5fec937ea4964184d4d6c4f0b9551564f821e1c3575907639036d9b90/bleach-1.5.0-py2.py3-none-any.whl
Requirement already satisfied, skipping upgrade: werkzeug>=0.11.10 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5.0) (0.14.1)
Requirement already satisfied, skipping upgrade: markdown>=2.6.8 in c:\users\yuu.pc7\anaconda3\envs\my2\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5.0) (3.0.1)
Collecting html5lib==0.9999999 (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5.0)
  Using cached https://files.pythonhosted.org/packages/ae/ae/bcb60402c60932b32dfaf19bb53870b29eda2cd17551ba5639219fb5ebf9/html5lib-0.9999999.tar.gz
Building wheels for collected packages: html5lib
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: C:\Users\yuu.PC7\AppData\Local\pip\Cache\wheels\50\ae\f9\d2b189788efcf61d1ee0e36045476735c838898eef1cad6e29
Successfully built html5lib
Installing collected packages: html5lib, bleach, tensorflow-tensorboard, tensorflow
  Found existing installation: html5lib 1.0.1
    Uninstalling html5lib-1.0.1:
      Successfully uninstalled html5lib-1.0.1
  Found existing installation: bleach 2.1.4
    Uninstalling bleach-2.1.4:
      Successfully uninstalled bleach-2.1.4
Successfully installed bleach-1.5.0 html5lib-0.9999999 tensorflow-1.5.0 tensorflow-tensorboard-1.5.1

(my2) C:\Users\yuu.PC7>