Más contenido relacionado La actualidad más candente (20) Similar a 190925 python-windows (20) Más de Takuya Nishimoto (20) 190925 python-windows2. 1) Windows Subsystem for Linux
• macOS (homebrew) から移行しやすい
• ウェブアプリ開発で Windows ブラウザが使える
• シェルスクリプト / Linux CLI / node.js などと併用
• Windows 非対応のプロダクト
• Ansibleでサーバー管理
• マイコン開発
• USBシリアルを /dev/ttyS1 で使える
• 性能はWSL2で改善予定
2
3. WSLの導入
• Windows 10 64bit 限定(HomeでOK / Docker 不要)
• Windows + I
• 設定の検索「Windows の機能の有効化または無効化」
• Windows Subsystem for Linux を有効化
• Microsoft Store から Ubuntu を入手(無料)
• > wsl
• $ sudo apt install python3
• ソースから入れる場合は make altinstall
3
4. Python 処理系を使い分ける
• which python3 などで確認
• 処理系を指定して venv
• python3.7 -m venv venv
• /usr/local/bin/python3.7 -m venv venv
• . venv/bin/activate した後は python で ok
• /usr/bin/python = python2 のままにしておく
• PEP 394
4
5. WSL 環境での作業(エディタ)
• /mnt/c の下で作業する
• Windows のエディタで開発できる
• wsl$ に Windows から書き込まないこと
• /home などがある
• Visual Studio Code (VSCode)
• Remote - WSL extension
• Windows GUI で WSL 環境の作業
• Python も VSCode extension も WSL 側で動く
• Windows Terminal (現在 Preview)
• nano や emacs がちゃんと動く
5
7. 2) 公式 Python
• Windows 7 / 8.1 でも 32bit でも使える
• Windows アプリを開発・配布
• Windows API / Windows DLL を使える
• Everything で検索すると実績がわかる
• python.exe
• python3.exe / python3.dll
• python2.exe
7
8. 公式 Python の導入
• インストーラー
• オフライン版とオンライン版
• 32bit / 64bit
• chocolatey(後述)
• 使いたい Python をどう選ぶのか
• Windows + I → 設定の検索「環境変数を編集」
• PATH
8
9. which.bat で python の場所を確認
@echo off
for %%I in (%1 %1.com %1.exe %1.bat %1.cmd %1.vbs %1.js %1.wsf) do if exist %%~$path:I echo %%~$path:I
@IT:Windows TIPS -- Hint:whichコマンドを作る
https://www.atmarkit.co.jp/fwin2k/win2ktips/319which/which.html
9
10. py.exe = Python Launcher
公式 Python と一緒に C:Windowspy.exe にインストール
> py -0p または py --list-paths
Installed Pythons found by py Launcher for Windows
-3.8-64 C:Python38python.exe *
-3.7-32 C:UsersnishimotzAppDataLocalProgramsPythonPython37-32python.exe
-2.7-32 C:Python27python.exe
> py -3.8-64 -m pip --version
> py -3-32 -m venv venv
> py -2 hoge.py
10
11. Chocolatey
コマンドプロンプト(管理者権限)
> choco install python → 3.7.x (64bit)
> choco install python --pre → 3.8.0-b4 (64bit) c:Python38
> choco install python2 → 2.7.16 (32bit) c:Python27
> choco upgrade all -y
> refreshenv
11
12. 3) Store 版 Python
• 2019年春に爆誕した「新しい公式 Python」
• Microsoft が推奨(後述)
• きれいにアンインストールできるという話
• ストアアプリの制約、まだ仕様が不安定という話
• Windows 10 64bit 限定
• TEMP やレジストリに書き込めない
• py.exe で選べない
12
14. Store 版 Python の導入
• python.exe が Microsoft Store に誘導
• Version 1903 から
• あるいは Store で Python 3.7 を検索
• PSF 謹製 Python 3.7 をインストール(無料)
C:Users**AppDataLocalMicrosoftWindowsApps
ここに python3.exe / python.exe などがある
その下のディレクトリ PythonSoftwareFoundation.Python.3.7_*** に実体
14
15. アプリ実行エイリアス
• Windowsの設定
• 検索「アプリ実行エイリアスの管理」
• 項目
• python / python3 / python3.7
• pythonw / pythonw3*
• idle / idle3* / pip / pip3*
• アプリインストーラー python.exe / python3.exe
• off にすると
• PATHが通らない状態になる
• 他の Python を優先させたい場合に off にする
15
16. 4) Anaconda
• Jupyter 環境構築が簡単
• 数値計算が公式より速いらしい
• TensorFlow in Anaconda (with GPU)
• https://www.anaconda.com/tensorflow-in-anaconda/
• venv / pip ではなく conda
• py.exe で選択できない(以前はできた)
16
17. Anaconda Prompt
> python [Enter]
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
• 作業場所を指定して Jupyter Notebook を使う
> cd c:hoge
> jupyter notebook fuga.ipynb
17
18. 対話環境の終わり方
• 非 Windows の Python
• >>> [Ctrl+D]
• Windows の Python
• >>> [Crtl+Z] → [Enter]
• 共通
• >>> exit() → [Enter]
18