简体   繁体   English

在安装需要 numpy 的包时,如何防止 pip 仅用 numpy 替换 numpy+mkl?

[英]How to prevent pip from replacing numpy+mkl with just numpy when installing packages that require numpy?

When I pip install (or pip install --upgrade ) packages that require numpy , they have a tendency to uninstall my existing numpy+mkl (which has a high enough version to satisfy the numpy version requirement).当我pip install (或pip install --upgrade )需要numpy的包时,它们倾向于卸载我现有的numpy+mkl (它有足够高的版本来满足numpy版本要求)。 Afterwards, they install numpy without +mkl , which causes problems for other packages that do require MKL.之后,他们在没有+mkl的情况下安装numpy ,这会导致其他需要 MKL 的包出现问题。 An example for which this happens is gym (which has 'numpy>=1.10.4' in its install_requires in setup.py ).发生这种情况的一个例子是gym (它在setup.pyinstall_requires中有'numpy>=1.10.4' )。

I understand that this is related to the +mkl suffix that probably somehow messes with the versions, and understand I can fix it afterwards by downloading and installing numpy+mkl from https://www.lfd.uci.edu/~gohlke/pythonlibs/ , but it gets annoying to manually do this every time over again when upgrading a package like gym to a new version.我知道这与可能以某种方式混淆版本的+mkl后缀有关,并且我知道我可以通过从https://www.lfd.uci.edu/~gohlke/pythonlibs下载并安装numpy+mkl来修复它/ ,但是在将 gym 之类的软件包升级到新版本时,每次都手动执行此操作会很烦人。 Is there any way to prevent numpy+mkl from getting uninstalled during the pip install --upgrade ?有什么方法可以防止numpy+mklpip install --upgrade --upgrade 期间被卸载?


For me, this is happening on Windows 10 , Python 3.6 .对我来说,这发生在Windows 10Python 3.6上。 I did not yet check if the same happens on Linux , but would be interested in an answer for that too if it's different there.我还没有检查Linux上是否发生了同样的情况,但如果那里有所不同,我也会对这个问题的答案感兴趣。

My currently installed version of numpy+mkl (which often gets automatically uninstalled) is 1.13.3+mkl .我当前安装的numpy+mkl版本(通常会自动卸载)是1.13.3+mkl

Using --upgrade-strategy , as suggested by cgohlke in a comment, addresses this problem.正如 cgohlke 在评论中所建议的那样,使用 --upgrade --upgrade-strategy可以解决这个问题。 So, taking the example where we want to install gym from scratch without it replacing our existing numpy+mkl installation with regular numpy , the full command to run is:因此,以我们想从头开始安装gym而不用常规numpy替换我们现有的numpy+mkl安装为例,要运行的完整命令是:

pip install --upgrade-strategy only-if-needed gym

Or, if we just want to upgrade an existing installation , we also add --upgrade或者,如果我们只想升级现有安装,我们还添加--upgrade

pip install --upgrade --upgrade-strategy only-if-needed gym

I have found that some packages force pip to reinstall numpy.我发现有些软件包会强制 pip 重新安装 numpy。 The safest (and only) way to ensure that numpy is installed with mkl (from conda) is to uninstall using conda and pip and then reinstall using conda:确保使用 mkl(来自 conda)安装 numpy 的最安全(也是唯一)方法是使用 conda 和 pip 卸载,然后使用 conda 重新安装:

conda uninstall numpy
pip uninstall nump
conda install numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM