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

相关推荐
dhdjjsjs9 分钟前
Day35 PythonStudy
python
毕设源码-朱学姐28 分钟前
【开题答辩全过程】以 基于Java的人体骨骼健康知识普及系统为例,包含答辩的问题和答案
java·开发语言
lly20240631 分钟前
Julia 函数
开发语言
sheji341634 分钟前
【开题答辩全过程】以 基于JAVA的社团管理系统为例,包含答辩的问题和答案
java·开发语言
如竟没有火炬38 分钟前
四数相加贰——哈希表
数据结构·python·算法·leetcode·散列表
周杰伦_Jay41 分钟前
【GOFrame】模块化框架与生产级实践
开发语言·gitlab·github
背心2块钱包邮1 小时前
第9节——部分分式积分(Partial Fraction Decomposition)
人工智能·python·算法·机器学习·matplotlib
Simon席玉1 小时前
C++的命名重整
开发语言·c++·华为·harmonyos·arkts
chao1898441 小时前
MATLAB中的多重网格算法与计算流体动力学
开发语言·算法·matlab
木盏1 小时前
三维高斯的分裂
开发语言·python