anantya_saadhak
anantya_saadhak

Reputation: 19

Pyinstaller can't create the .exe file

I wanted to convert my python code into an executable and came across Pyinstaller package. However while running pyinstaller --onefile my_python_code.py from my cmd prompt it throws an ImportErrorWhenRunningHook for with numpy. I don't know where/ how to find the required module in my machine as per the error instructions. Can anybody please help me understand the error message and overcome the challenge?

edit:

... 281436 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks'... c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import distributor_init Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init.py", line 22, in from . import multiarray File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\multiarray.py", line 12, in from . import overrides File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\overrides.py", line 7, in from numpy.core._multiarray_umath import ( ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\matplotlib_init_.py", line 107, in from . import cbook, rcsetup File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\matplotlib\cbook_init_.py", line 28, in import numpy as np File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py", line 140, in from . import core File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init_.py", line 48, in raise ImportError(msg) ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from "c:\programdata\anaconda3\envs\geo_env\python.exe" * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

281586 INFO: Loading module hook 'hook-matplotlib.py' from 'c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks'... c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import distributor_init Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init.py", line 22, in from . import multiarray File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\multiarray.py", line 12, in from . import overrides File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\overrides.py", line 7, in from numpy.core._multiarray_umath import ( ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\matplotlib_init_.py", line 107, in from . import cbook, rcsetup File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\matplotlib\cbook_init_.py", line 28, in import numpy as np File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py", line 140, in from . import core File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init_.py", line 48, in raise ImportError(msg) ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from "c:\programdata\anaconda3\envs\geo_env\python.exe" * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

281757 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks'... 281769 INFO: Loading module hook 'hook-numpy.core.py' from 'c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks'... c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import distributor_init c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import distributor_init Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init.py", line 22, in from . import multiarray File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\multiarray.py", line 12, in from . import overrides File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\overrides.py", line 7, in from numpy.core._multiarray_umath import ( ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 2, in File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py", line 140, in from . import core File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init_.py", line 48, in raise ImportError(msg) ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from "c:\programdata\anaconda3\envs\geo_env\python.exe" * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init_.py", line 22, in from . import multiarray File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\multiarray.py", line 12, in from . import overrides File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core\overrides.py", line 7, in from numpy.core._multiarray_umath import ( ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\pkgutil.py", line 493, in find_loader spec = importlib.util.find_spec(fullname) File "c:\programdata\anaconda3\envs\geo_env\lib\importlib\util.py", line 94, in find_spec parent = import(parent_name, fromlist=['path']) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy_init_.py", line 140, in from . import core File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\numpy\core_init_.py", line 48, in raise ImportError(msg) ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from "c:\programdata\anaconda3\envs\geo_env\python.exe" * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\utils\hooks_init_.py", line 289, in get_module_file_attribute loader = pkgutil.find_loader(package) File "c:\programdata\anaconda3\envs\geo_env\lib\pkgutil.py", line 499, in find_loader raise ImportError(msg.format(fullname, type(ex), ex)) from ex ImportError: Error while finding loader for 'numpy.core' (<class 'ImportError'>:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from "c:\programdata\anaconda3\envs\geo_env\python.exe" * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found. )

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\depend\imphook.py", line 409, in _load_hook_module self.hook_module_name, self.hook_filename) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\compat.py", line 593, in importlib_load_source return mod_loader.load_module() File "", line 407, in _check_name_wrapper
File "", line 907, in load_module File "", line 732, in load_module File "", line 265, in _load_module_shim File "", line 696, in _load File "", line 677, in load_unlocked File "", line 728, in exec_module File "", line 219, in call_with_frames_removed File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py", line 29, in pkg_base, pkg_dir = get_package_paths('numpy.core') File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\utils\hooks_init.py", line 506, in get_package_paths file_attr = get_module_file_attribute(package) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\utils\hooks_init.py", line 308, in get_module_file_attribute raise ImportError('Unable to load module attribute') from e ImportError: Unable to load module attribute

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\programdata\anaconda3\envs\geo_env\lib\runpy.py", line 193, in run_module_as_main "main", mod_spec) File "c:\programdata\anaconda3\envs\geo_env\lib\runpy.py", line 85, in run_code exec(code, run_globals) File "C:\ProgramData\Anaconda3\envs\geo_env\Scripts\pyinstaller.exe_main.py", line 7, in File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller_main.py", line 114, in run run_build(pyi_config, spec_file, **vars(args)) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller_main_.py", line 65, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build exec(code, spec_namespace) File "C:\Users\pandas10\Desktop\sa_fmcg_forecast\py_exe\fmcg_forecast.spec", line 17, in noarchive=False) File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\building\build_main.py", line 242, in init self.postinit() File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in postinit self.assemble() File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\building\build_main.py", line 419, in assemble self.graph.process_post_graph_hooks() File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks module_hook.post_graph() File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph self._load_hook_module() File "c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\depend\imphook.py", line 413, in _load_hook_module self.hook_module_name, self.hook_filename) PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_numpy_core required by hook for module c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py. Please check whether module __PyInstaller_hooks_0_numpy_core actually exists and whether the hook is compatible with your version of c:\programdata\anaconda3\envs\geo_env\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py: You might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller.

Note: I am using Anaconda and working in a separate environment than python base or default.

Upvotes: 0

Views: 4006

Answers (2)

Ewindar
Ewindar

Reputation: 31

Based on the log, obviously you are using the Anaconda python distribution. the Import error is happening cause the mkl-service's DLL can't be found, which should be located in:

C:\Users\\anaconda3\Library\bin

or

C:\Users<username>\anaconda3\envs\<env_name>\Library\bin

The most likely reason why the necessary DLLs can't be found (assuming mkl-service has been installed correctly) is the absence of the above directory in the PATH environment variable.

The mentioned path is usually prepended to the PATH by the Anaconda Prompt before build, so one solution is to run the command in the Anaconda Prompt.

Other solutions include:

  1. Either append the mentioned directory to the PATH globally (by editing the PATH variable in the Windows Settings), or
  2. Find a way to temporarily append it to the PATH (for the duration of your code's execution), specific to your development environment.

Upvotes: 0

XTRAP
XTRAP

Reputation: 118

After reading the whole log file, it seems like the installer did not download all the packages. I strongly recommend uninstalling the package and reinstalling it.

For uninstalling - Open a command or terminal window (depending on the operating system) cd into the project directory. pip uninstall pyinstaller

And to reinstall - If u r using PyCharm, just go to terminal on the bottom and type - pip install pyinstaller

If u r using other things (I don't know about what you may be using) - On Windows - press Windows Key + R and type cmd

On Mac - go to Finder/ Applications/ Terminal (I may be wrong)

Now type the command - pip install pyinstaller

See the installation process and the packages being installed, if there is already a package installed, it will skip its installation, and if one isn't installed, pip will install it.

Upvotes: 0

Related Questions