Cannot load mkl_intel_thread.dll on python executable - python

I'm trying to create an executable python program that runs on windows without python being installed, for this I'm using cx_Freeze. But I get the following error: "Cannot load mkl_intel_thread.dll"
On my PC, which has python installed (miniconda3), I built the executable using cx_Freeze, and when I ran the executable I also would get "Cannot load mkl_intel_thread.dll". I fixed this by going to my python folder, Library\bin, and copied the mkl_intel_thread.dll file to where the executable is placed. The problem is, when moving the whole folder to another PC (without python installed), this error reappears, even though the mkl_intel_thread.dll is in the folder.
File that I want to distribute (plot.py):
import matplotlib.pyplot as plt
a = [0, 1, 2]
b = [0, 2, 0]
plt.fill(a, b, 'b')
plt.show()
cx_Freeze setup file (setup.py):
import cx_Freeze
import sys
import matplotlib
import numpy
import os
os.environ['TCL_LIBRARY'] = "C:\\Miniconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Miniconda3\\tcl\\tk8.6"
executables = [cx_Freeze.Executable("plot.py")]
build_exe_options = {"includes":['numpy.core._methods',
'numpy.lib.format', 'matplotlib.backends.backend_tkagg']}
cx_Freeze.setup(
name = "script",
options = {"build_exe": build_exe_options},
version = "0.0",
description = "A basic example",
executables = executables)

EDIT:
Try to copy all files starting with mkl you find under Library\bin or numpy\core into the build folder, as well as libiomp5md.dll, see Python Pyinstaller 3.1 Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll and cx_freeze converted GUI-app (tkinter) crashes after pressing plot-Button.
Once you have found out which file(s) need(s) to be manually copied, you can let cx_Freeze include the necessary file(s) by using the include_files list of the build_exe options (see code snippet below). If necessary, you can use a tuple (source, destination) as item in the include_files list to let cx_Freeze copy a file from source to a specific destination into the build directory, see the cx_Freezedocumentation.
I see further potential problems in the setup script you've posted in your question:
include the whole numpy packages using the packages list of the build_exe options, it is easier and maybe safer
it is safer to dynamically find out the location of the TCL/TK DLLs
for cx_Freeze 5.1.1, the TCL/TK DLLs need to be included in a lib subdirectory of the build directory
In summary, try t o use
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
build_exe_options = {'packages': ['numpy'],
'includes': ['matplotlib.backends.backend_tkagg'],
'include_files': [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join('lib', 'tcl86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join('lib', 'tk86t.dll'))
# add here further files which need to be included as described in 1.
]}
in your setup script.

A similar issue affects cx_Freeze 6.1 or 6.2: the executable does not launch, either without error message or with
INTEL MKL ERROR: The specified module could not be found. mkl_intel_thread.dll.
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Configuration:
Windows 10
Python 3.8.5 installed from https://www.python.org/
numpy 1.19.1+mkl installed with pip using wheel from https://www.lfd.uci.edu/~gohlke/pythonlibs/
various python modules installed using pip
This is also observed with Python 3.6.8 or earlier versions of numpy such as e.g. 1.18.4+mkl or 1.19.0+mkl.
I've observed that cx_Freeze includes 3 DLLs mkl_rt.dll, python38.dll, and vcruntime140.dll in the subdirectory lib\numpy\core of the build directory, whereas the original installation does not contain any DLL in the subdirectory site-packages\numpy\core (all DLLs are in site-packages\numpy\DLLs). If I manually remove mkl_rt.dll from the subdirectory lib\numpy\core of the build directory after building the application with cx_Freeze, the issue disappears and the application works.
This solution can be implemented by adding the following code at the end of the setup.py script:
numpy_core_dir = os.path.join(dist_dir, 'lib', 'numpy', 'core')
for file_name in os.listdir(numpy_core_dir):
if file_name.lower().endswith('.dll'):
file_path = os.path.join(numpy_core_dir, file_name)
os.remove(file_path)
where dist_dir is the build directory generated by cx_Freeze (passed to the build_exe option).

Just copy these four files in cx_freeze generated build folder
mkl_core.dll
mkl_def.dll
mkl_intel_thread.dll
mkl_mc3.dll

Manage to find a solution to this by downgrading numpy==1.18.2 from numpy==1.19.1 when using cx_Freeze==6.5.3.

Related

FileNotFoundError: scipy.libs

I'm trying to build an exe file using cx_Freeze.
But when I run the resulting file I get an error:
FileNotFoundError: ..\build\exe.win-amd64-3.8\lib\scipy.libs
Please tell me how to fix this problem?
I run the following code:
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["torch", 'tensorflow']}
target = Executable(
script='sub.py'
)
setup(
name='my',
options={'build_exe': build_exe_options},
executables=[target]
)
I had this exact problem, this is only a short term fix but if you search for 'scipy.libs' in your python install location 'site-packages' folder (or virtual environment if you're using one) and copy/paste it into the libs folder in your build it should solve the issue.
I'll edit my answer if I come across the root cause and a more permanent fix...
Hope this helps!
You can use the include_files option of the build_exe command. According to the cx_Freeze documentation, you can use a tuple (source, destination) in the include_files list to let cx_Freeze copy a file to a specific destination into the build directory:
this list will contain strings or 2-tuples for the source and destination; the source can be a file or a directory (in which case the tree is copied except for .svn and CVS directories); the target must not be an absolute path
Accordingly, try to add the following lines to your setup.py file:
import os
import scipy
scipy_libs_source = os.path.join(os.path.dirname(os.path.dirname(scipy.__file__)), 'scipy.libs')
scipy_libs_destination = os.path.join('lib', 'scipy.libs')
include_files = [(scipy_libs_source, scipy_libs_destination)]
build_exe_options = {'include_files': include_files,
'packages': ['torch', 'tensorflow']}

cx_freeze executable - Py_Initialize: Unable to load the file system codec

I'm using cx_freeze to pack my Python script as a standalone executable.
The exe is running fine on the machine it was packed (with python 3.5 and all the relevant packages).
But when I copied the folder cx_freeze created to another machine the I got this error:
My cx_freeze script:
import sys
import numpy
import os.path
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name = "DocSum",
version = "1.0",
options = {"build_exe": {"packages":["idna","asyncio", "encodings","numpy", "jinja2.ext"]}},
description = "DocSumRESTfulServer",
executables = [Executable("DocSumRESTfulServer.py", base = None)]
)
Any idea what could be the reason? I thought that the exe should be a standalone (run on machines without python). Am I wrong?
It seems that not all dependencies were compiled successfully.
If you want to have a standalone executable, I recommend pyinstaller.
Just pip install it then:
pyinstaller.exe --onefile yourFile.py
The --onefile flag is used to package everything into a single executable. Your executable file would be found on the dist folder.
You could also try this site.
I had the same problem. At the end I discovered that I need to copy also my python37.dll and the lib directory.
If the exe, dll and the directory are on the same directory, it works.
I would like to have a single exe too.

When using cx_Freeze and tkinter I get: "DLL load failed: The specified module could not be found." (Python 3.5.3)

When using cx_Freeze and Tkinter, I am given the message:
File "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.
Some things to note:
I want to use Python 3+ (Currently using 3.5.3, 32-bit). Don't really care about a specific version, whatever works.
My project has multiple files I need to compile. As far as I can tell, that leaves me with cx_Freeze or Nuitka. Nuitka had problems of its own.
I am using Windows 10 Home Edition, 64-bit
Here is my current setup.py:
from cx_Freeze import setup, Executable
import sys
build_exe_options = {"packages": ["files", "tools"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="Name",
version="1.0",
description="Description",
options={"build_exe": build_exe_options},
executables=[Executable("main.py", base=base)],
package_dir={'': ''},
)
I have tried many solutions from all corners of the internet. Including but not limited to:
Multiple versions of python (and the corresponding cx_Freeze/Tkinter versions)
Both 32-bit and 64-bit versions
Replacing Tkinter with easygui (apparently easygui needs Tkinter to work)
Checking the PATH variables
Restarting my computer (Don't know what I expected)
Uninstalling other versions of python and repairing the correct version
Placing the following in my compile bat file (Definetly the correct paths):
set TCL_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\tcl\tcl8.6
set TK_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\tcl\tk8.6
Placing the following in my setup.py:
options={"build_exe": {"includes": ["tkinter"]}}
Along with:
include_files = [r"C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\DLLs\tcl86t.dll",\
r"C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\DLLs\tk86t.dll"]
(And yes, those were included in setup() in one way or another)
Thanks for any help, it's greatly appreciated. And yes, I have looked at just about every solution to this problem on this site. Hoping someone could help me find yet another solution since my problem seems to be persistent.
Found a solution!
I had to copy the tk86t.dll and tcl86t.dll files from my python directory's DLLs folder into the build folder with the main.py I was trying to compile.
This, in conjunction with having
set TCL_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35\tcl\tcl8.6
set TK_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35\tcl\tk8.6
at the top of my compile.bat, and including
"include_files": ["tcl86t.dll", "tk86t.dll"]
in my build_exe_options in setup.py, seems to have done the trick.
Here is my current setup.py:
from cx_Freeze import setup, Executable
import sys
build_exe_options = {"packages": ["files", "tools"], "include_files": ["tcl86t.dll", "tk86t.dll"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="Name",
version="1.0",
description="Description",
options={"build_exe": build_exe_options},
executables=[Executable("main.py", base=base)],
package_dir={'': ''},
)
And here is my compile.bat (updated to show all steps):
#echo off
set TCL_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6
set TK_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6
RD /S /Q "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin"
mkdir "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin"
xcopy /s "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll" "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin\tcl86t.dll"
xcopy /s "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll" "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin\tk86t.dll"
cd "C:\Users\VergilTheHuragok\Desktop\PythonProject\"
cxfreeze main.py --target-dir "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin" --target-name "launch.exe"
pause
I found this solution here.
to solve this problem just copy the files
1.tcl86t.dll
2.tk86t.dll
from this path C:\Users\h280126\AppData\Local\Programs\Python\Python36-32\DLLs
and placed in our .exe path
C:\Users\h280126\PycharmProjects\my_tool\build\exe.win32-3.6
it is working fine :)
After fixing these issues cx_freeze was still unable to import the dependencies of pandas (namely numpy). To fix this I literally copied and pasted the entire folders into the directory of the .py file I was trying to compile. The executable needs to be in the same directory (so it isn't necessarily stand-alone) but it runs with pandas and numpy.

Is it possible to use cx_freeze on a python 3 project using the pip module?

I am writing an installation program for a larger program I am writing, and I am using CxFreeze to convert it to an executable file, however, when I run the .exe file, it crashes with the line "import pip", and brings up (as shown below), so basically my question is: Is it possible to use CxFreeze on an application with pip imported?
Edit:
Here are all the files I am using:
setup.py (V1):
from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
version = "1",
description = "ARTIST installation file",
executables = [Executable("Install ARTIST.py"), Executable("C:\\Python34\\Lib\\site-packages\pip\\__init__.py")],
)
This brings up the error:
setup.py (V2):
from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
version = "1",
description = "ARTIST installation file",
executables = [Executable("Install ARTIST.py"],
options = {"build_exe": {"packages":[pip]}}
)
This brings up an error in the setup.bat file:
Edit:
If anyone wants to look at the website where I am publishing the larger program, here is the link:
alaricwhitehead.wix.com/artist
Edit2:
this is the error i get when i use py2exe:
Edit3:
here is a copy of the code:
https://www.dropbox.com/s/uu46iynm8fr8agu/Install%20ARTIST.txt?raw=1
please note: I didn't want to have to post a link to it, but it was too long to post directly.
The are two problems in your setup script. The first problem is that you specified extra modules to include in your frozen application under the packages option of the build_exe command: packages is for specifying which packages of your application you need to include, for the external modules (such as pip) you need to use includes. The second problem is that you need to pass to includes a list of strings of modules and not the module itself:
setup(
name=("ARTIST"),
version="1",
description="ARTIST installation file",
options={
'build_exe': {
'excludes': [], # list of modules to exclude
'includes': ['pip'], # list of extra modules to include (from your virtualenv of system path),
'packages': [], # list of packages to include in the froze executable (from your application)
},
},
executables=[
Executable(
script='run.py', # path to the entry point of your application (i.e: run.py)
targetName='ARTIST.exe', # name of the executable
)
]
)

can't find module 'cx_Freeze__init__'

I'm trying to convert my Python project to a standalone executable, in order to run it on other servers that don't have Python installed.
Command used:
python setup.py build > build.log
When I try to run the resulting exe, it always spits out the following error message:
zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal Python error: unable to locate initialization module
Current thread 0x00000b8c (most recent call first):
I've tried to define all the libraries I'm using throughout my project in the setup.py module, though this has made no difference.
I have also added the DLL files to include (described in the post cx-freeze doesn't find all dependencies).
The project consists of the following libraries (output of pip list):
cx-Freeze (4.3.2)
docopt (0.6.1)
pip (1.5.4)
psutil (2.0.0)
pywin32 (218)
requests (2.2.1)
setuptools (2.2)
virtualenv (1.11.4)
WMI (1.4.9)
Contents of setup.py:
include_files=[
(r'C:\Python34\Lib\site-packages\pywin32_system32\pywintypes34.dll', 'pywintypes34.dll'),
(r'C:\Python34\Lib\site-packages\pywin32_system32\pythoncom34.dll', 'pythoncom34.dll'),]
build_exe_options = dict(
packages=['os', 'concurrent.futures', 'datetime', 'docopt', 'email.mime.text', 'configparser', 'enum',
'json', 'logging', 'psutil', 'requests', 'smtplib', 'socket', 'subprocess', 'sys', 'threading', 'time',
'wmi', 'pythoncom'],
excludes=[],
include_files=include_files)
executable = Executable(
script = 'pyWatch.py',
copyDependentFiles = True,
base = 'Console')
setup( name= "pyWatch",
version= "0.1",
options= {"build_exe": build_exe_options},
executables= [executable])
cx_freeze's output (too large to paste here): http://pastebin.com/2c4hUSeD
All help would be greatly appreciated!
instead of cx_freeze which is last version updated on 2014
there is a module called pyinstaller which is last version update on 2016
pyinstaller
also easy to use just pyinstaller myscript.py and bam

Categories

Resources