分类: 电脑技术
作者: admin

Python的虚拟环境

在运行pip3 install命令时候出现了下面的错误提示
XML/HTML代码
  1. error: externally-managed-environment  
  2.   
  3. × This environment is externally managed  
  4. ╰─> To install Python packages system-wide, try apt install  
  5.     python3-xyz, where xyz is the package you are trying to  
  6.     install.  
  7.   
  8.     If you wish to install a non-Debian-packaged Python package,  
  9.     create a virtual environment using python3 -m venv path/to/venv.  
  10.     Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make  
  11.     sure you have python3-full installed.  
  12.   
  13.     If you wish to install a non-Debian packaged Python application,  
  14.     it may be easiest to use pipx install xyz, which will manage a  
  15.     virtual environment for you. Make sure you have pipx installed.  
  16.   
  17.     See /usr/share/doc/python3.11/README.venv for more information.  
  18.   
  19. 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.  
  20. hint: See PEP 668 for the detailed specification.  
出现以上错误提示,可以在虚拟环境中解决
XML/HTML代码
  1. python3 -m venv .venv
  2. source .venv/bin/activate
然后再运行pip install或者pip3 install安装程序就可以正常进行了。