j4n7's answer was very helpful, however, it may or may not be buggy. compat.base_prefix
uses backslashes (at least for me) but they then concatenate with "/Lib/site-packages/numpy/core"
(forward slashes).
>>> from PyInstaller import compat
>>> compat.base_prefix
'C:\\Python34'
>>> mkldir = compat.base_prefix + "/Lib/site-packages/numpy/core"
>>> mkldir
'C:\\Python34/Lib/site-packages/numpy/core'
As you can see, it produces both forward and backward slashes in a path.
Here are my steps that allowed me to bundle the numpy mkl files into onefile. Note that my particular app uses matplotlib and the problem I was experiencing was everytime I clicked a button (tkinter) to execute the plot, the app crashed.
Steps
First: Make a build of your app using:
pyinstaller --onefile --windowed yourpythonappnamehere.py
Second: Open the .spec
file and add this to it. Obviously make sure the below files actually exist first. You may not have Python34
so just a friendly warning not to copy blindly.
mkl_dlls = [('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_avx.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_avx2.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_avx512.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_core.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_def.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_intel_thread.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_mc.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_mc3.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_rt.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_sequential.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_tbb_thread.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx2.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx512.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_cmpt.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_def.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc2.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc3.dll', ''),
('C:\\Python34\\Lib\\site-packages\\numpy\\core\\libiomp5md.dll', '')]
Third: where it says binaries=None
, change to binaries=mkl_dlls
.
a = Analysis(['yourpythonappnamehere.py'],
pathex=['C:\\Users\\...\\Documents\\...'],
binaries=mkl_dlls,
datas=None,
....
Fourth: Re-run the first step. When your app is built, go into the dist
folder and launch your app. I hope it works for you!
UPDATE: If you get Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll but you can clearly see that mkl_intel_thread.dll IS IN your program directory, go to numpy/core and literally copy all the files with .dll extensions that you don't have and paste them into your program's directory and re-run. If it works, great, but you might want to delete one at a time to figure out which ones you need and which ones you don't.