Xcode编译的时候运行python脚本

写好了python脚本,结果python3 xxx.py运行会失败,原来是xode的shell环境与Terminal环境不一致,所以需要source ~/.zshrc刷新一下环境变量。

为了不影响系统的python环境,我们采用了虚拟环境。先创建一个venv环境(第二个venv是名字,可以任意修改),并激活它

复制代码
python3 -m venv venv
source venv/bin/activate

由于我们python中使用了sqlcipher这个模块。所以需要在系统重安装这个库。

复制代码
brew install sqlcipher

接下来pip3 install sqlcipher3,很遗憾会报错,提示'sqlcipher/sqlite3.h' file not found.

需要再~/.zshrc中添加sqlcipher的头文件与库文件,这样编译sqlcipher3才能成功。

复制代码
export C_INCLUDE_PATH="$(brew --prefix sqlcipher)/include"
export LIBRARY_PATH="$(brew --prefix sqlcipher)/lib"

为了解决系统python3与brew安卓的python冲突,如果需要优先使用brew安装的python, 请在~/.zshrc中添加下面这行

复制代码
eval "$(/opt/homebrew/bin/brew shellenv)"

这样就可以使用python虚拟环境来执行python。

相关推荐
新*25 分钟前
从一段 WebSocket 代码聊开:bytes 不是 zlib、binaryType 决定一切,15MB 大消息的零拷贝优化
javascript·python·websocket·性能优化·blob·zlib·arraybuffer
卷无止境2 小时前
mathmodel-figure-templates 以及两个上手案例
后端·python
锋行天下3 小时前
服务器 Python 2.7 装不了 langgraph-cli?用本地生成 Dockerfile 曲线救国
人工智能·后端·python
一条大祥脚3 小时前
深入理解 PyTorch FlexAttention:从 Score Mod 到 Mask Mod 的稀疏加速之道
人工智能·pytorch·python·注意力机制·flex attention·可编程注意力
2601_967980114 小时前
Python自动化办公:模块、库与样式调整教程
python·excel·自动化办公·openpyxl·样式调整
长沙三为智能科技4 小时前
GEO与传统SEO的5个关键差异:排名与被引用、关键词与答案型的全维度对比
python·aigc·seo·ai搜索·geo优化
量化分析码农6 小时前
【Python量化趋势跟踪实战 02】突破买入总被假突破坑:通道系统与入场时机
python
Agent世界6 小时前
多平台登录态巡检:cookie 判据为什么会撒谎
python
量化分析码农7 小时前
【Python量化趋势跟踪实战 01】均线多头排列就是趋势开始吗:过滤与确认
python
用户298698530147 小时前
Python 实战:把代码写入 Word 文档的两种实现方式
后端·python·api