Python开发环境配置

2025-10-29 19:00:00
丁国栋
原创 15
摘要:如何在Linux系统中安装使用Python项目。

Python安装一些包或者依赖时提示:


pip3 install XXX
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.12/README.venv for more information.
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.
这时最好是使用虚拟环境:



python3 -m venv .
source ./bin/activate
pip3 install xxx


提示:如果使用 apt 安装 pip3,应该使用 apt install python3-pip3

感慨:以前本来挺喜欢 Python的,我知道 Python 这个语言其实很优秀,只是有些项目把 Python 用的挺差的,特别是一些Python开发的命令行工具,一旦报错就是满屏幕糟糕的报错提示,这点跟 PHP 差距不小🤔🤔

--

发表评论
博客分类