なぜwarpをつかうのか
初心者がCUIを使用する際にハードルとなるのが、コマンドがうまく動かなかった際(または、エラーが出た際)に、解決方法を見つけることです。通常、これまでの作業を中断して、本またはネットでリファレンスを引きながら対処することになります。
そこで、AIターミナルアプリwarpの出番です。この記事ではwarpの使い方の詳細は解説しませんが、warpを使用するとコマンドが動かない・エラーが出た際に解決方法を提案してくれます。
例えば、uvで新しいプロジェクトを開始するとします。
$ uv init new-project
そうすると、warpはコマンド実行後に、次のアクションを提案してくれます。
~ (0.167s)
uv init new-project
Initialized project `new-project` at `/Users/xxxxx/new-project`
AI: Change directory to the new project. ⌘ ↵
⌘
+↵
キーを叩くと、以下のように進みます。
User: Change directory to the new project.
AI: I'll change directory to the new-project directory for you.
~ (0.024s)
cd /Users/xxxxx/new-project
Done! I've changed to the /Users/xxxxx/new-project directory. You're now in the new-project directory.
また、コマンド入力ウインドウには以下のように表示されているので、右矢印キー→
を打てばコマンドが補完されます。
cd /Users/xxxxx/new-project →
AIをかませると時間がかかるので、慣れてきたらAIを利用せずに手打ちか自動補完を使えば、効率アップとなります。
Qtを利用したPythonのGUIライブラリであるPySide6をインストールしてみます。
$ uv pip install pyside
~/new-project git:(main) (0.191s)
uv pip install pyside
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
AI: Create a virtual environment. ⌘ ↵
AIが、まず仮想環境を作ってくださいと提案してきます。
uv venv →
→
キーを叩いてコマンドを補完し、実行します。
uv venv
Using CPython 3.9.6 interpreter at: /Applications/Xcode.app/Contents/Developer/usr/bin/python3
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
source .venv/bin/activate →
というように、warpを使うと次のアクションを提案してくれます。
→
入力後、改めて、uv pip install pyside
でインストールを試みます。
uv pip install pyside
Resolved 1 package in 53ms
× Failed to build `pyside==1.2.4`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)
[stdout]
only these python versions are supported: [(2, 6), (2, 7), (3, 2), (3, 3), (3, 4)]
hint: This usually indicates a problem with the package or the build environment.
今度は、pythonのバージョンとpysideのバージョンが合っていないようですね。また、Pythonのバージョンが3.9.6と古いので、現在インストールされている安定版3.12.11にアップデートします。
User: Install the latest stable python
AI: I'll install the latest stable Python using uv, which can manage Python versions.
✓ uv python install
The installation completed, but it installed Python 3.9.23. Let me install the latest stable version explicitly:
✓ uv python install 3.12
Perfect! I've installed Python 3.12.11, which is the latest stable version. The installation includes:
- Python 3.12.11 has been installed
- The executable is available as `python3.12`
Note that there's a warning about the PATH. If you want to use the installed Python versions directly, you can either:
1. Run `export PATH="/Users/xxxxx/.local/bin:$PATH"` to add it to your current session
2. Run `uv python update-shell` to automatically update your shell configuration
You can also use `uv python list` to see all installed Python versions, and `uv python pin 3.12` to set Python 3.12 as the default for this project.
さらに、再びpyside
をインストールしようとすると、インストールしたいバージョンはPySide6ですか?と聞いてきます。pyside
→pyside6
として、インストール。
uv pip install pyside6
Resolved 4 packages in 45ms
Installed 4 packages in 135ms
+ pyside6==6.9.1
+ pyside6-addons==6.9.1
+ pyside6-essentials==6.9.1
+ shiboken6==6.9.1
uv pip list
で確認。
✓ uv pip list
Here are the currently installed packages in your virtual environment:
• pyside6 (6.9.1) - The main PySide6 package for Qt GUI development
• pyside6-addons (6.9.1) - Additional PySide6 modules
• pyside6-essentials (6.9.1) - Essential PySide6 components
• shiboken6 (6.9.1) - The binding generator used by PySide6
These packages provide everything you need to create Qt-based GUI applications with Python.
無事に、PySide6がインストールできました。
以上のように、warpを使用すると解決方法の検索から実行までターミナル内で行うことができます。無料で利用できるFreeプランでは、AI機能利用枠は月間150回までという制限がありますが、本格的にコードを書くプログラマーでもない限り、それほど困らないと思います。
「manコマンドやコマンドの--helpオプションを使えば?」という意見もあると思いますが、そもそも初心者は、どこを探したらよいかわからないから初心者なのであって、AIが解決方法を提案してくれるだけでも、たいへん助かります。
以上で下準備は終わりです。次は基礎編に進みます。