Apple silicon Monterey设备上Austin命令行剖析Python程序失败求助
操作与报错回顾
初始执行VSCode生成的命令:
austin -i 100 --pipe /usr/bin/python3 /Users/mh/p131.py报错:
👾 It looks like you are trying to profile a process that is not a Python process. Make sure that you are targeting the right application. If the Python process is actually a child of the target process then use the -C option to discover it automatically.
添加
-C选项后执行:austin -i 100 -C --pipe /usr/bin/python3 /Users/mh/p131.py报错:
👽 Not a Python process.
🚼 It looks like you are trying to profile a process that is not a Python process, and that has not spawned any child Python processes. Make sure that you are targeting the right application.
具体解决方案
1. 匹配Python与Austin的架构
Apple Silicon上Python分ARM64原生和x86_64(Rosetta转译)两种架构,需确保和Austin版本一致:
- 检查当前Python架构:
若输出/usr/bin/python3 -c "import platform; print(platform.machine())"arm64,确认Austin是ARM64编译版;若为x86_64,则需用x86版本Austin或通过Rosetta运行Austin。
2. 使用原生ARM64 Python路径
系统默认的/usr/bin/python3可能走Rosetta转译,试试Homebrew安装的原生ARM64 Python:
austin -i 100 --pipe /opt/homebrew/bin/python3 /Users/mh/p131.py
未安装Homebrew的话先执行:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install python
3. 授予Austin系统权限
Monterey的隐私限制可能阻止Austin访问进程:
- 打开「系统设置」→「隐私与安全性」→「完全磁盘访问权限」
- 点击加号,添加Austin可执行文件(通常在
/usr/local/bin/austin或/opt/homebrew/bin/austin) - 重启终端后重试命令
4. 移除--pipe选项尝试
--pipe在Apple Silicon上可能存在兼容性问题,直接运行:
austin -i 100 /usr/bin/python3 /Users/mh/p131.py
需要保存数据的话用重定向:
austin -i 100 /usr/bin/python3 /Users/mh/p131.py > profile_data.txt
5. 更新Austin到最新版
确保使用最新版本修复架构兼容问题:
brew upgrade austin # Homebrew安装的情况
或从官方渠道重新下载对应ARM64的二进制文件替换现有安装。
内容的提问来源于stack exchange,提问作者mhaselup

