python3.12使用pip安装包错误问题
缘起
最近升级ubuntu系统,发现python3没法用了(传统艺能,不知道为什么每次升级python,一对的三方库、python行为、pip行为的变化),所以查了下解决方案,这里记录下。
解决方案
直接使用pip3安装包,报如下的错误:
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.
这特么什么鬼,我安装一个包直接跑,干嘛要搞个虚拟环境,我要真有需求,不会自己创建吗?
解决方案
直接忽视警告就完了,直接--break-system-packages
,使用如下配置:
python3 -m pip config set global.break-system-packages true
总结
比较烦python的版本升级后和pip、安装的三方包的各种问题,非常的坑,什么虚拟环境我需要的时候在搞就好,直接默认要虚拟环境就非常蠢了。。
发表评论