Pythonを勉強するのにオススメの本はコチラ!

こんにちは,しまさん(@shimasan0x00)です.
先日新しいiPad Proを購入しました.
そこでiPadを使ってプログラミングしたい!(主にPythonとかPythonとか).
そこで見つけたアプリ「Pythonista3」の紹介をします.
今回はインストールとpipが使えるbashのようなシェル「Stash」のインストールを行います.
環境
iPad Pro 11inch (2018)
iOS 12.1
スポンサーリンク
Pythonista3とは

Pythonista3はiOSでPythonを動作させることができるIDEといえます.
コード補完やスニペット等の機能もあり,Python2系,3系を動かすことができます.
また,後述する「Stash」を使用すればpipで外部ライブラリをインストールすることができます.
ただ,機械学習系のライブラリがインストールできないですね(というよりc依存のライブラリが無理そう).
pygame等を用いた簡単なゲームなんかは動かすことができます.

私の使用しているMacbook Proよりもスペック高いので処理についてはあまり心配していません.

スポンサーリンク
Stashをインストール
では,Pythonista3をさらに便利にするためのシェル「Stash」をインストールしましょう.
メインの画面を右にスライドさせるとコンソールに移動します.
その中で以下のコマンドを実行しましょう.
import requests as r; exec(r.get('http://bit.ly/get-stash').text)
そうすると以下の画面が出てくるはずです.

成功したらPythonista3を起動し直してください.
そうすると自分の「iPad」内にlanch_stash.pyが追加されていると思います.
追加されているそのファイルを選択して,実行しましょう.

おお〜〜,無事「Stash」が起動しましたね.

使えるコマンドはhelpと打ったら出てきます.
このスクリーンショットには収まらないくらいのコマンドは使用可能です.


StashをiPadのホームから使えるようにする
先程Stashが使えるようになりましたが,毎回StashのPythonファイルまで行って実行するのは面倒ですよね.
なのでiPadのホーム画面から起動できるようにします.
まずはlanch_stash.pyに移動して右上にある工具マークを押して「Add to Home Screen」を選んでください.
※現在は工具マークから「Shortcuts」を選び,「Home Screen Icon」を選ぶことで可能です(Add to Home…のままの人もいます).

好きなタイトルやアイコンの設定をして「Continue」を押してください.

そうするとブラウザが開かれます.
指示どうりにホーム画面に追加しましょう.

そうすると… おお〜〜〜〜ちゃんとホーム画面に追加されていますね.

※それでもうまくいかない方へ
現在Safariを開く際に白い画面でlocalhostと表記されるだけでアイコンが追加されない問題が発生しているようです.
pythonistaフォーラムでもこの問題点について指摘されています.
解決策として,ショートカットアプリを使用することを推奨されています.
Pythonistaアプリ上でHome Screen Iconを押していたところをPythonista URLを選んで「Copy URL」を選択します.
ショートカットアプリで新規ショートカットを作成し,「URLを開く」を探して追加します.
そのURLの部分にコピーしたURLをペーストすると完成します.
スポンサーリンク
さいごに
今回はiOSでのPythonプログラミングで必要不可欠なPythonista3の紹介でした.
PCで使うPythonには及びませんがある程度のプログラミングはできそうです.
今後もっと発展して機械学習をiPadだけでできたら楽しいだろうなと思います.
p.s.
ゼロから作るDeep Learningシリーズならライブラリをmatplotlibとnumpyのみしか使わないので学習可能です.
あぁ,iPad(iOS)にVSCodeみたいなエディタあったらいいのに.

最近,iPad , iPhone(iOS)内にローカルでjupyter notebookを立ち上げて利用できるCarnetsというものが出ています.
興味有る方はチェックしてみてください.
追記:使用できるコマンド一覧
alias: List or define shell aliases.
cat: Print the contents of the given files.
cd: Change the current working directory.
clear: Clear the stash console output window
cowsay:
cp: Copy a file or directory. Multiple source files may be specified if the destination is
crypt: File encryption for stash
curl: Transfer a URL
cut: Print selected parts of lines from each FILE to standard output.
dropbox_setup: manage your dropbox configuration.
du: Summarize disk usage of the set of FILEs, recursively for directories.
easy_config: a graphical config manager for StaSh
echo: Print all arguments to stdout, separated by spaces.
edit: Used to create/open and edit files.
exit: Exit the current subshell, optionally with a specific status. If no
fg: Bring a background job to foreground.
find: Find files in specified paths
ftpserver: Simple FTP Server
gci: Interface to pythons built-in garbage collector
gh: Usage: gh <command></command> [...]
git: Distributed version control system
grep: Search a regular expression pattern in one or more files
head: Print the first 10 lines of the given files.
httpserver: Simple HTTP Server With Upload (https://gist.github.com/UniIsland/3346170)
jobs: List all jobs that are currently running.
kaggle: Kaggle API
kill: Terminate a running job.
latte:
ls: List information about files (the current directory by default)
mail: Send messages/files from stash.
man: Display help for a command in $STASH_ROOT/bin/ or a topic, or list all commands if no name is given.
mc: easily work with multiple filesystems (e.g. local and FTP) synchronously
md5sum: Get md5 hash of a file or string.
mkdir: Create a new directory. The parent directory must already exist,
monkeylord: easiliy manage monkey-patches. See 'man monkeypatching' for more help.
more: Display output one screen page at a time (optionally with numbered lines)
mount: mount a filesystem.
mv: Move (rename) a file or directory to a new name, or into a new
openin: Open file in an external app.
pbcopy: Copy one or more files to the system clipboard
pbpaste: Writes the contents of the system clipboard to a file.
ping: Usage:
pip: Install and manage python packages
printenv: List current environment variables and values.
printhex: Print the given files' content and hexadecimal byte values.
ptinstaller: Installer program to help install tools registered on the Pythonista Tools GitHub repo.
pwd: Print the current working directory.
python: Simulates a console call to python [-m module][-c cmd] [file] [args]
python3: Simulates a console call to python3 [-m module][-c cmd] [file] [args]
quicklook: Open file in Quick Look.
rm: Remove (delete) files and directories.
rmdir: Remove empty directory
scp: Secure Copy - Copy files between local and remote
selfupdate: Selfupdate StaSh from the GitHub repo.
sha1sum: Get sha1 hash of a file or string.
sha256sum: Get sha256 hash of a file or string.
slugify: A Python Slugify application that handles Unicode
sort: Sort standard input or given files to standard output
source: Read and execute commands from a shell script in the current environment.
sqlite: sqlite3 shell modeled after sqlite3 command-line.
ssh: OpenSSH client for stash.
ssh-keygen: Generates RSA/DSA SSH Keys.
stashconf: List and set StaSh configuration options
tail: Print the last 10 lines of the given files.
tar: Create and extract tar, gzip, bz2 archives.
telnet: Simple telent client.
totd: Tip of the day
touch: Update the modification times of the given files, and create them if
tqdm: ???
umount: unmount a filesystem.
uniq: Print standard input or files, omitting repeated lines
unzip: Extract a zip archive into a directory.
version: Show information about this StaSh installation.
wc: Print newline, word, and byte counts for each FILE, and a total line if
webviewer: Opens the given URL in the webbrowser or an App.
wget: Download a file from a url.
whatis:
which: Locate a command script in BIN_PATH. No output if command is not found.
wol: usage: wol.py [-h] [-i ip] [-p port] mac addresses [mac addresses ...]
xargs: Construct argument list(s) and execute utility
zip: Package and compress (archive) files and directories