問題描述
win10安裝xgboost 的時候發現pip命令不能使用,報錯內容如下:
from pip._internal import cmdoptions
ImportError: cannot import name cmdoptions
此問題爲pip損壞所致
執行pip --version 命令仍然報出此錯誤
解決方法:
參照官網 https://packaging.python.org/tutorials/installing-packages/ 中的一段文字:
If pip isn’t already installed, then first try to bootstrap it from the standard library:
python -m ensurepip --default-pip
If that still doesn’t allow you to run pip:
Securely Download get-pip.py [1]
Run python get-pip.py. [2] This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.
Warning Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.
通過如上內容做如下操作:
1、 首先執行命令: python -m ensurepip --default-pip
2、 下載 get-pip.py 文件 地址爲 https://bootstrap.pypa.io/get-pip.py
3、 最後從命令行進入到 get-pip.py 所在的目錄,執行命令 : python get-pip.py
注意 此步驟執行的時候可能會報出權限錯誤, 此時應執行 python get-pip.py --user
執行 pip --version 查看pip是否安裝完成