Python pip 安装模块时报错更换源及error: externally-managed-environment解决方案
Python pip 安装模块时报错更换源及error: externally-managed-environment解决方案
只要所安装的模块是存在的,那么如果产生报错信息 多半是因为网络原因。因为默认pip 是国外的源。下载不稳定 速度慢。 解决方案 更换国内源解决此问题。
这里列举了一些国内源
pip国内源:
清华镜像:https://pypi.tuna.tsinghua.edu.cn/simple
中科大镜像:https://pypi.mirrors.ustc.edu.cn/simple
豆瓣镜像:http://pypi.douban.com/simple
阿里镜像:http://mirrors.aliyun.com/pypi/simple
搜狐镜像:http://mirrors.sohu.com/Python/
华中科大镜像:http://pypi.hustunique.com/
使用方法:
临时使用 加个 i 镜像源地址 就可以了
pip install 模块名 -i http://mirrors.aliyun.com/pypi/simple/
如果觉得每次安装都要指定镜像源地址的话。 可以使用全局
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
成功执行 在C盘下创建了配置文件。 后面下载的模块会去阿里云这个仓库进行下载
如果安装出现以下报错
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-Kali-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 pypy3-venv installed.
If you wish to install a non-Kali-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.
For more information, refer to the following:
* https://www.kali.org/docs/general-use/python3-external-packages/
* /usr/share/doc/python3.13/README.venv
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.
在刚才pip安装的命令后面输入 --break-system-packages 即可解决
pip3 install -r requirements.txt --break-system-packages (--break-system-packages选项的作用是告诉pip忽略当前环境的外部管理,并强制安装Python包到当前环境中。)
虽然有一定缺点存在。但可以快速解决当前的问题