Operit AI 中文文档 下载 App

Python + Node.js:Operit 里的移动端开发应急

核心场景:高铁上的临时工位

Operit 的 Ubuntu chroot 把 Python 和 Node.js 开发环境塞进了口袋。典型使用场景:高铁上 SSH 连服务器 → git clone → 改代码 → 跑测试 → commit——一节车厢就是一间临时工位。

Python 开发

环境准备

# Python 3 是 chroot 默认预装的,确认版本
python3 --version  # Ubuntu 24 是 Python 3.12+

# pip 预装确认
pip3 --version

写脚本

# 创建脚本
vim ~/test.py

# 内容示例
cat << 'EOF' > ~/test.py
import requests
import json

resp = requests.get("https://api.github.com/repos/AAswordman/Operit")
data = resp.json()
print(f"Stars: {data['stargazers_count']}")
EOF

# 运行
python3 ~/test.py

pip 装包

pip3 install requests httpx
pip3 install playwright  # 自动安装浏览器

pip 镜像源(国内加速):

pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

虚拟环境

cd ~/projects/myapp
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

虚拟环境在 chroot 里的隔离和标准 Linux 完全一致。

Node.js 开发

环境准备

Ubuntu 官方源自带的 Node.js 版本可能较旧(Ubuntu 24 是 Node 18),建议用 nvm 装最新稳定版:

# 装 curl(如果还没装)
apt install curl -y

# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# 重载 shell(或重新打开终端)
source ~/.bashrc

# 装 Node LTS
nvm install --lts
node --version   # 应显示 20.x 或更新
npm --version

项目开发

# 新建项目
mkdir -p ~/projects/nodeapp && cd ~/projects/nodeapp
npm init -y
npm install express

# 创建入口文件
cat << 'EOF' > index.js
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello from Operit!'));
app.listen(3000);
EOF

# 运行
node index.js &

# 访问(Operit 的 Web 工作区功能会把 localhost 暴露出来)
curl http://localhost:3000

在 Operit 对话里跑代码

除了直接进终端输命令,你也可以在 Operit 对话里用自然语言触发代码执行:

"在终端里写一个 Python 脚本,抓取 Operit GitHub 仓库的 star 数量并打印"

Agent 会自动创建文件、写代码、执行命令、返回结果——和你手动进终端做的事情完全一样,但省去了敲命令的麻烦。

和手机文件系统的交互

chroot 和 Android 宿主的文件系统是隔离的,但 Operit 提供了桥接层:

物理限制提醒

手机屏幕和虚拟键盘在长代码编辑时确实不如键鼠。建议: