Xcode搭建Python运行环境

1,113 阅读1分钟

需要先熟悉几个指令:

brew install python ‘or’ Xcode runing Python3 安装
​
which python ‘or’ which python3  获取路径
​
python -V ‘or’ python3 -V  获取版本
​
brew search python 全局查找python

sudo rm -rf /Library../python 移除

安装python

Xnip2022-10-18_22-56-23.jpg

1.检查macOS环境下的python环境

python -V ‘or’ python3 -V

output: Python 3.8.9

2.如果不存在或需要更新可以用

brew install python ‘or’ Xcode runing Python3

output:/usr/bin/python3

创建项目

[1] new project target 【External Build System】

Xnip2022-10-18_22-23-09.jpg

[2] Build tool 【python path】

Xnip2022-10-18_22-24-26.jpg

[3.1] 选中Info

(1)取消选中 DEbug executable (2)选中指定 python exec

Xnip2022-10-18_23-09-21.jpg

Xnip2022-10-18_22-27-21.jpg

Xnip2022-10-18_23-08-08.jpg

[3.2] 选中Arguments

执行 Arguments Passed On Launch 增加python文件

Xnip2022-10-18_22-38-02.jpg

[3.3] 选中Options

执行 Working Directory 路径

Xnip2022-10-18_23-11-00.jpg

[4]新建文件 Empty

Xnip2022-10-18_23-14-34.jpg

[5]运行项目

Xnip2022-10-18_23-20-44.jpg

疑难排查

可能遇到的问题: [Errno 2] No such file or directory

上图3.3这一步,1.检查是否勾选,2.检查路径是否正确

可能遇到的问题:[Errno 1] Operation not permitted

需要添加python3 并开启访问权限

Xnip2022-10-18_23-18-48.jpg

可能遇到的问题: 上图3.1搜索到指定python,但无法添加

在要使用的python上层文件夹目录下,执行命令创建一个同步链接,例 ln python3.10.8 python318,就可以添加了