--- lang:ja-jp ###### tags: --- # Windows 環境構築 [TOC] ## 環境 **Windows10** Intel i7 : 8th Gen ### 目標 - WSLでUbuntu - うざくないUbuntuに - jupyter lab + HEASoftでPyXspec環境 ## 手順 ### 手始めに - Win : Chrome DL - Win, Ubuntu : wsl導入 http://www.atmarkit.co.jp/ait/articles/1806/28/news043.html - Ubuntu : X410 DL Microsoft Storeで高品質なX Window serverのX410を購入 - sudo apt install apt-file `sudo apt-file update` HEASoftのinstallなどで依存ファイルが抜けていた時に、それがどのパッケージに含まれているか検索してくれるapt-fileをDL ### heasoft - heasoft DL : [Xspec($\in$ heasoft)の導入](/5sw6ekv1RwSyckjbL61iwg) 本命の一角。NASAからのDLは(容量のわりに)かなり時間がかかる。 可能なら誰かが最近DLした圧縮ファイルをもらいたい。(2.5 GB) また、make && make install に時間がかかる。(~数時間) 以下のerrorは、事前の依存パッケージDLができていなかっただけ? ```bash checking for ar... noar configure: error: ar not found in your $PATH. See your sysdamin. ``` sudo apt install binutils ```bash checking for gmake... no checking for make... no ``` sudo apt install build-essential ```bash checking for X... no configure: error: Required file /usr/include/X11/Xlib.h not found! ``` sudo apt install libx11-dev ```bash WARNING: pkg-config is not installed ``` sudo apt install pkg-config ```bash configure: error: No curses header-files found ``` sudo apt-get install libncurses5-dev ```bash configure: error: cannot compile a simple Fortran program ``` sudo apt install gfortran - Ubuntu : ds9 DL ds9は公式ページからDLして、解凍。PATHの通った場所にシンボリックリンクを貼る。 - Win : google drive DL GoogleさまのGoogle Drive (Backup and Sync)をDL - Win : start menu 調整 C:\ProgramData\Microsoft\Windows\Start Menu\Programs Start Menuにはびこっていた出荷時の不要なプログラム群を整理 - Ubuntu : terminal DL `sudo apt install xfce4-terminal` xtermはあまりに古臭すぎるので…… - Win : Ubuntuのショートカットキー作成 -> Ctrl Alt T Start MenuからDesktopなどにUbuntuをドラッグしてショートカットを作成。 そのショートカットのプロパティを開き、キーボードショートカットとしてCtrl+Alt+Tを登録。 - Win : 便利aliasを適宜整備 - sas copy (ftpつながらない?DLダメ) -> DLできないのでLocalでもらう - Ubuntu : pip install sudo apt install python3-distutils curl -kL https://bootstrap.pypa.io/get-pip.py | sudo python3 sudo apt install python3-pip - jupyter lab sudo pip install jupyterlab - numpy, scipy, matplotlib sudo pip3 install numpy scipy matplotlib astropy どうせそのうち使うpackageたちをDL - ssh ssh NAME@HOST.jp -L 8080:HOST.jp:22 -X -C - PyXspec PyXspecのDocumentのBuild and Installの部分に沿って進める。 まずはhamkercに加筆する。 ```bash PYTHON_INC="-I/usr/include/python3.6m" PYTHON_LIB="-L/usr/lib/python3.6" ``` :::info PYTHON_INCやPYTHON_LIBに入れるべきpathはbashに`python3-config`をオプション付きで走らせて確認する。 `python3-config --cflags`の先頭部分を参考に`-I/usr/include/python3.6m` `python3-config --ldflags`の先頭部分を参考に`-L/usr/lib/python3.6` ::: 後でPython.hがないと言われるので`sudo apt install python-dev`しておく。 PYTHON_INCの場所(/usr/include/python3.6mなど)はPython.hがあるかどうかでも判断できる。 その後、ディレクトリを移動し、`hmake clean && hmake && hmake install` :::info hmakeはheasoftのinstall後に~/.bash_profileに記述を追加、sourceまで走らせて有効になる。(hmake=Heasoft MAKE) ::: この時点でのエラーは大抵、PYTHON_INCやPYTHON_LIBの設定ミスである。 `error: cannot convert ‘PY_SZ_TYPE* {aka int*}’ to ‘Py_ssize_t* {aka long int*}’` このエラーが出るようになると、(うまくいっていたはずの)heasoftのmakeをやり直しても躓くようになる。 heasoftのtar.gzファイルの解凍からやり直すとうまくいく。 PyXspecのBuildがうまくいったかどうかはその場でpython3を開き`import xspec`が通るかどうかで確認できる。 - Win, Ubuntu : BROWSER for jupyter lab WSLではjupyter labを起動しても、windows側のbrowserで自動で起動してくれない。 そこで、windows側のbrowserをこちらでリンク付きで勝手に呼び出す。 win_chrome8888などの名前で以下のスクリプトを保存し、`chmod 777 win_chrome8888`で権限を与え、PATHの通った場所にシンボリックリンクを貼る。 ```bash # win_chrome8888 #!/bin/bash cmd.exe /c start chrome.exe http://localhost:8888/ 2>/dev/null ``` `alias jup="win_chrome8888 ; jupyter lab"` その後、aliasでchromeとjupyter labが立て続けに起動するようにすれば万事解決。 - Win : 電源とスリープ設定 電源につないでいるときのスリープまでの時間を長くしたり。 特にNECのPCは初期のままでは蓋を閉じたときにスリープしないらしい。(改めて設定を保存すると直る。) - Win : node.js install [Node.js GitHub](https://github.com/nodesource/distributions/blob/master/README.md#debinstall) ```bash curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - sudo apt install -y nodejs ``` jupyterのextensionの一部はnode.jsを必要とするが、aptなどでnode.jsをDLしてもなぜか古いversionしかない。 上記のように手動でinstallする。 - qfits-tools, pandoc, imagemagick 特にqfits-toolsはdfits(fitsのheaderなどを非interactiveに与える)を含んでいる。 - Win : 起動時 https://support.microsoft.com/ja-jp/help/4026268/windows-10-change-startup-apps Win+R -> shell:startup X410.exeのショートカット貼り付け - Ubuntu : less syntax highlight `sudo apt install source-highlight` lessの表示にsyntax highlightを付ける。まずはハイライト用のファイルをaptでinstallする。 `find /usr/ -name src-hilite-lesspipe.sh -print 2>/dev/null`でその場所を探す。(/usr/share/source-highlight/src-hilite-lesspipe.shなど) ~/.bashrcなどにless用の環境変数を加筆する。 `export LESSOPEN='|/usr/bin/lesspipe | /usr/share/source-highlight/src-hilite-lesspipe.sh %s'` このように設定することで 1. シンタックスハイライトが有効になる。 2. 圧縮ファイル(binary)などを見たときに、解凍せずとも内容を確認できる。 - Win, Ubuntu : VSCode install _To use VS Code with the Windows Subsystem for Linux, please install VS Code in Windows and uninstall the Linux version in WSL. You can then use the 'Visual Studio Code' command in a WSL terminal just as you would in a normal command prompt._ https://code.visualstudio.com/docs/remote/wsl WSL用のVSCodeはWindows用でDLし、remote-WSLという拡張機能を利用すべし、とのこと。この拡張機能により、VSCode内のterminalがwslになる。 ~~`alias code="cmd.exe /c code $(wslpath .)"` 起動用のaliasも用意する。~~ alias expl="explorer.exe ." - jupyter lab extensions TOC : 目次タブ機能 sudo jupyter labextension install @jupyterlab/toc コード整形機能 sudo pip install autopep8 sudo pip install jupyterlab_code_formatter sudo jupyter labextension install @ryantam626/jupyterlab_code_formatter sudo jupyter serverextension enable --py jupyterlab_code_formatter ```json { "shortcuts":[ { "command":"jupyterlab_code_formatter:autopep8", "keys":[ "Ctrl M" ], "selector":".jp-Notebook.jp-mod-editMode" } ] } ``` git対応機能 sudo jupyter labextension install @jupyterlab/git sudo pip install jupyterlab-git sudo jupyter serverextension enable --py jupyterlab_git sudo jupyter labextension install @lckr/jupyterlab_variableinspector 自動変換機能 sudo pip install jupytext jupyter lab --generate-config c.ContentsManager.default_jupytext_formats = "ipynb,python//py" sudo jupyter lab build - wsl2移行 : めっっちゃ重かった(メモリ16GB使用で2時間) cacheが消えていないだけだった -> empty.exeを適宜使用すれば、そこまでかからない。 - wsl2は(Vmmemのものとして)memory cacheが残り続けるバグがある。 %UserPrifile%/wsl.confにmemory上限を設定 cache削除用のaliasも設定。(必要に応じてbashで実行すると劇的にcacheが解放される) - Docker Desktop for WSL2 wsl2になると、DockerがUbuntu側でも利用できる - symbolyc link, tab competition symbolic linkのディレクトリ名をTab補完したときに`/`がつかないので、無駄にひと手間増える設定を修正。 ただし、ディレクトリを指すシンボリックリンクを削除したいときに`/`付きの場合、シンボリックリンクファイル自体ではなく、参照先のディレクトリを削除しようとするので注意。(-rがなければ削除はされないが) cat ~/.inputrc set mark-symlinked-directories on - mute beep sound ~/.inputrc set bell-style none うざすぎるbeep音を消す。あれがあるとTab補完を使うのも億劫になる……。 - Logicool Options