我最近卸载了Enthought Canopy 32位的一个很好的工作副本,并安装了Canopy版本1.1.0(64位)。当我尝试使用sklearn拟合模型时,内核崩溃,并且出现以下错误:
The kernel (user Python environment) has terminated with error code 3. This may be due to a bug in your code or in the kernel itself.
Output captured from the kernel process is shown below.
OMP: Error #15: Initializing libiomp5md.dll, but found mk2iomp5md.dll already initialized.
OMP: Hint: This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
相同的代码在Canopy的32位下运行得很好。该代码实际上只是linear_model.SGDClassifier(loss ='log')的简单拟合(Logistic回归错误相同,未尝试其他模型)
我该如何解决?
我有同样的问题,来自numpy中相互冲突的安装以及来自顶篷。通过编写来解决它:
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
不是一个很好的解决方案,但是它为我完成了工作。
几乎可以肯定,您可以通过设置环境参数来克服此错误
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
但是,建议不要设置此参数(如错误消息中所述)。相反,您可以尝试通过运行以下命令来设置conda环境,而不使用英特尔数学内核库:
conda install nomkl
如果您使用的版本是基于MKL的,那么执行此操作后,您可能需要再次安装一些软件包(尽管conda应该为您完成此操作)。如果没有,那么您将需要执行以下操作:
安装通常包含MKL的软件包,或依赖于包含MKL的软件包,例如
scipy
,numpy
和pandas
。 Conda将安装这些软件包的非MKL版本及其依赖项(请参见here)
对于macOS,nomkl
是一个不错的选择,因为MKL提供的优化实际上已经由Apple的Accelerate Framework提供,后者已经使用OpenMP。实际上,这就是触发错误(“ ... OpenMP运行时的多个副本...”)的原因,看来(如this answer中所述)。