Windows + Python + Conda

昨日は第4回の「すごい広島 with Python」でした。
前回の報告:

Interface as Mimesis


このときに py.exe による Windows 環境での Python の切り替えについて詳しく書かなかったので、このブログでその続きを書きます。
昨日は「もくもく会」だったので、ディープラーニングの環境構築にとりかかりました。行ってみると「話したいので聞いてほしい」という参加者が多数いらっしゃって、楽しかったのですが、私の作業はあまり進まなかったです。。
やってみたこと:Windows に Theano を(GPU対応なしで)インストールした。
環境:Windows 10 Home (64bit)
もともと入っている Python:Python 2.7 (32bit) と Python 3.6 (32bit)
もともとできていたこと:
Python 3.6 を入れるとついてくる py.exe を使って py -2 または py -3 で両者を切り替えることができた。
今回 theano をインストールした手順:

  1. Miniconda Windows 64bit installer をデフォルトのオプションでインストール
  2. コマンドプロンプトで
    > conda install numpy scipy mkl
  3. つづいてコマンドプロンプトで
    > conda install theano

theano の動作確認:

C:\work>python
 Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import theano
 >>> from theano import tensor as T
 >>> x1 = T.scalar()
 >>> w1 = T.scalar()
 >>> w0 = T.scalar()
 >>> z1 = w1 * x1 + w0
 >>> net_input = theano.function(inputs=[w1, x1, w0], outputs=z1)
 >>> print('Net input: %.2f' % net_input(2.0, 1.0, 0.5))
 Net input: 2.50
 >>> import numpy as np
 >>> x = T.fmatrix(name='x')
 >>> x_sum = T.sum(x, axis=0)
 >>> calc_sum = theano.function(inputs=[x], outputs=x_sum)
 >>> ary = [[1, 2, 3], [1, 2, 3]]
 >>> print('Column sum:', calc_sum(ary))
 Column sum: [ 2. 4. 6.]
 >>> theano.config.floatX = 'float32'
 >>> ary = np.array([[1, 2, 3], [1, 2, 3]], dtype=theano.config.floatX)
 >>> print('Column sum:', calc_sum(ary))
 Column sum: [ 2. 4. 6.]

この状態で python コマンドは今回インストールした Miniconda の Python になっています。
この状態での Python 処理系の切り替えの確認:

C:\work>py -3.6
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\work>py -3.6-32
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\work>py -2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

公式 Python は 32bit 版を入れて Anaconda 系 Python は 64bit 版を入れる、という使い分けが必要にはなりますが py.exe ですべての環境を切り替えられることを確認しました。
なお Theano の動作確認は Python 機械学習プログラミング 達人データサイエンティストによる理論と実践 第13章を引用しました。
 


投稿日

カテゴリー:

投稿者:

タグ: