解决venv中无法安装numpy的问题(Could not build wheels for numpy which use PEP 517)

懒人包

在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。
https://ithelp.ithome.com.tw/upload/images/20210714/20139482LTnje3cI81.jpg

爬文後得知是pip版本的问题,原先pip的版本是19.0.3
https://ithelp.ithome.com.tw/upload/images/20210714/201394823thjYJBnzv.jpg

於是更新pip,执行

pip install --upgrade pip

但执行完却出现Could not install packages due to an EnvironmentError: [WinError 5] 存取被拒。
https://ithelp.ithome.com.tw/upload/images/20210714/20139482SrLKcXypar.jpg

爬文後得知在pip install --upgrade pip 後面加上--user可以解决此状况,所以执行

pip install --upgrade pip --user

这时候却出现Cannot open D:\python projects\install_numpy\venv\Scripts\pip3-script.py
https://ithelp.ithome.com.tw/upload/images/20210714/20139482cULSNtL0Q0.jpg
原来是在执行pip install --upgrade pip时,原本的pip被删出了,导致目前的venv中没有pip。

这时只好重新删除原先的venv,再建立一个新的venv,再执行一次

pip install --upgrade pip --user

这时出现Successfully installed pip-21.1.3,看似是更新成功了
https://ithelp.ithome.com.tw/upload/images/20210714/201394826jDbmynldD.jpg

这时再度尝试安装numpy,执行

pip install numpy

但又再次出现Could not build wheels for numpy which use PEP 517 and cannot be installed directly。
https://ithelp.ithome.com.tw/upload/images/20210714/20139482LTnje3cI81.jpg

奇怪,怎麽pip已经更新了,还是出现一样的错误?

这时再确认一次pip的版本,发现还是19.0.30
https://ithelp.ithome.com.tw/upload/images/20210714/201394822ALQaJOexX.jpg
原来--user会让pip将package安装在user目录下的资料夹,不会安装在venv内,这时候只好想别的办法来更新pip。

统整一下,到目前为止我们试过了

pip install --upgrade pip
pip install --upgrade pip --user

两者都无法更新venv内的pip

爬文後得知也可以用easy_install更新pip
於是执行

easy_install -U pip

https://ithelp.ithome.com.tw/upload/images/20210714/20139482wUfit4v8mP.jpg
没有任何红字出现,应该是成功了

这时执行

pip -V

确认pip版本更新到21.1.3
https://ithelp.ithome.com.tw/upload/images/20210714/20139482Yf4iHq36D8.jpg

再次尝试安装numpy,执行

pip install numpy

https://ithelp.ithome.com.tw/upload/images/20210714/20139482USZHAXp5Oj.jpg

终於安装成功了,谢天谢地

结论

  1. Could not build wheels for package which use PEP 517 and cannot be installed directly原因出在pip版本太旧。
  2. 透过pip install --update pip可以更新pip,但如果出现Access Denied的时候,可以透过easy_install -U pip 更新pip。
  3. --user会将package安装在user目录底下,导致venv下的package没有变化。

<<:  建立自己Blog系列(二) github Setting

>>:  在 Lubuntu 18.04 上安装 CodeBlocks IDE 17.12

EPC 事件驱动图

EPC (Event Driven Process-Chain) 事件驱动流程链是一种流程图应用在业...

删除Windows事件纪录--听起来简单做起来难的销声匿迹

今天要研究是接续上篇的Windows XML Event Log (EVTX),要进入他的事件纪录本...

Day29 Swagger

年轻人不要看到标题就兴奋好吗? 以目前前後端分离的趋势,前端及後端工程师势必会由两个人以上来担任,那...

使用者帐号在Mendix要怎麽管理?

铁人赛来到第29天了! 既然应用程序都开发得差不多了,是时候来给Admin更多的权限了! 创建帐号连...

Day 15:Remove Duplicates from linked list

这题开始之前先来介绍一下Linked list(连结串列)的资料结构。 Linked list(连结...