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

相关推荐
zore_c几秒前
【C语言】数据在内存中的存储(超详解)
c语言·开发语言·数据结构·经验分享·笔记
程序员-周李斌6 分钟前
ArrayList 源码深度分析(基于 JDK 8)
java·开发语言·数据结构·算法·list
IT·小灰灰12 分钟前
深度解析重排序AI模型:基于硅基流动API调用多语言重排序AI实战指南
java·大数据·javascript·人工智能·python·数据挖掘·php
g***789114 分钟前
Python连接SQL SEVER数据库全流程
数据库·python·sql
y***031715 分钟前
Go基础之环境搭建
开发语言·后端·golang
子午17 分钟前
【卫星图像识别系统】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积网络+resnet50算法
人工智能·python·深度学习
___波子 Pro Max.19 分钟前
Python文档字符串指南
python
山海青风21 分钟前
用 Meta MMS-TTS + Python在本地把藏文文本变成藏语语音
python·音视频
前端程序猿i28 分钟前
前端判断数据类型的所有方式详解
开发语言·前端·javascript
摸爬滚打李上进40 分钟前
Pycharm编辑HTML文件注释问题
python·pycharm·django·bootstrap·html5