在venv下,執行
pip install --upgrade pip
當上述指令失敗時,執行
easy_install -U pip
在venv下安裝numpy的時候,出現Could not build wheels for numpy which use PEP 517 and cannot be installed directly。
爬文後得知是pip版本的問題,原先pip的版本是19.0.3
於是更新pip,執行
pip install --upgrade pip
但執行完卻出現Could not install packages due to an EnvironmentError: [WinError 5] 存取被拒。
爬文後得知在pip install --upgrade pip 後面加上--user可以解決此狀況,所以執行
pip install --upgrade pip --user
這時候卻出現Cannot open D:\python projects\install_numpy\venv\Scripts\pip3-script.py
原來是在執行pip install --upgrade pip時,原本的pip被刪出了,導致目前的venv中沒有pip。
這時只好重新刪除原先的venv,再建立一個新的venv,再執行一次
pip install --upgrade pip --user
這時出現Successfully installed pip-21.1.3,看似是更新成功了
這時再度嘗試安裝numpy,執行
pip install numpy
但又再次出現Could not build wheels for numpy which use PEP 517 and cannot be installed directly。
奇怪,怎麼pip已經更新了,還是出現一樣的錯誤?
這時再確認一次pip的版本,發現還是19.0.30
原來--user會讓pip將package安裝在user目錄下的資料夾,不會安裝在venv內,這時候只好想別的辦法來更新pip。
統整一下,到目前為止我們試過了
pip install --upgrade pip
pip install --upgrade pip --user
兩者都無法更新venv內的pip
爬文後得知也可以用easy_install更新pip
於是執行
easy_install -U pip
沒有任何紅字出現,應該是成功了
這時執行
pip -V
確認pip版本更新到21.1.3
再次嘗試安裝numpy,執行
pip install numpy
終於安裝成功了,謝天謝地