Mac Python 安装依赖出错 error: externally-managed-environment

Mac Python 使用 ip3 install -r requirements.txt 出错

bash 复制代码
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:
    
    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz
    
    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with
    
    brew install pipx
    
    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.
    
    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.
    
    Read more about this behavior here: <https://peps.python.org/pep-0668/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

[notice] A new release of pip is available: 24.0 -> 25.1.1
[notice] To update, run: python3.12 -m pip install --upgrade pip

解决方案:

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

重新运行 pip3 install -r requirements.txt

相关推荐
听情歌落俗3 分钟前
MATLAB3-2数据存储-台大郭彦甫
开发语言·数学建模·matlab·矩阵
程序员杰哥7 分钟前
什么是Jmeter? Jmeter工作原理是什么?
自动化测试·软件测试·python·测试工具·jmeter·职场和发展·测试用例
C19 分钟前
商城购物系统自动化测试报告
python·功能测试·selenium
云天徽上26 分钟前
【数据可视化-112】使用PyEcharts绘制TreeMap(矩形树图)完全指南及电商销售数据TreeMap绘制实战
开发语言·python·信息可视化·数据分析·pyecharts
ACEEE12221 小时前
Stanford CS336 | Assignment 2 - FlashAttention-v2 Pytorch & Triotn实现
人工智能·pytorch·python·深度学习·机器学习·nlp·transformer
NG WING YIN1 小时前
Golang關於信件的
开发语言·深度学习·golang
Sunny_yiyi1 小时前
Java根据模版导出PDF文件
java·开发语言·pdf
橘子132 小时前
C++实战:搜索引擎项目(二)
开发语言·c++·搜索引擎
iChochy2 小时前
[开源免费] iGTTS(Gemini TTS) 文本转语音(TTS)的命令行工具。
python·tts·gemini