python 创建虚拟环境

发布时间:2024年01月16日

为啥需要创建虚拟环境
在ubuntu直接pip安装的错误,规避自己安装的包与系统使用包之间的冲突

?  ~ pip3 install fastapi
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.11/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.

使用venv

创建

python -m venv MY_ENV

激活

source MY_ENV/bin/activate

退出

deactivate

参考

https://blog.csdn.net/qq_42951560/article/details/124224972

文章来源:https://blog.csdn.net/b1tb1t/article/details/135624164
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。