3

After building my exe, when I run it I get an error saying that it failed to import numpy.core.multiarray.

What I have already tested:

  • Updated numpy to latest version
  • Checked if I have more than one version of numpy
  • The file multiarray is inside the build/../numpy/core/multiarray
  • If i run python on console i can "from numpy.core import multiarray" without any problem

Packages I use: Easygui, Opencv2, pytesseract, os, pillow, regex

I'm running python 3.6.1 on W10

This is my setup.py.

    from cx_Freeze import setup, Executable
    import os

    os.environ['TCL_LIBRARY'] = r'C:\Users\Farinha\Anaconda3\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Users\Farinha\Anaconda3\tcl\tk8.6'

    includes      = []
    include_files = [r"C:\Users\Farinha\Anaconda3\DLLs\tcl86t.dll", \
                     r"C:\Users\Farinha\Anaconda3\DLLs\tk86t.dll"]


    setup(name='InstantScale',
        version = '0.1',
        description='Parse stuff',
        options = {"build_exe": {"includes": includes, "include_files": include_files}},
        executables = [Executable("main.py")])

And the error when i run a bat to pause the console

ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "C:\Users\Farinha\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\Farinha\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "main.py", line 2, in <module>
ImportError: numpy.core.multiarray failed to import

All help welcome, thanks in advance

Xantium
  • 11,201
  • 10
  • 62
  • 89
rdFarinha
  • 41
  • 1
  • 3

3 Answers3

1

Copy the numpy packages directly into your directory.

then add these lines :

import numpy.core._methods 
import numpy.lib.format

more information in this post

loki
  • 9,816
  • 7
  • 56
  • 82
nouja22
  • 11
  • 1
1

I Manage to fix it.

I added manually the package to the options.

includes      = []
include_files = [r"C:\Users\Farinha\Anaconda3\DLLs\tcl86t.dll", \
                 r"C:\Users\Farinha\Anaconda3\DLLs\tk86t.dll"]
packages = ["numpy"]

setup(name='InstantScale',
    version = '0.1',
    description='Parse stuff',
    options = {"build_exe":{"includes": includes, "include_files": 
          include_files, "packages":packages}}
Dr. Strange
  • 87
  • 11
Xantium
  • 11,201
  • 10
  • 62
  • 89
1

In my case, the error was happening when using optimize=2 in cxFreeze options. More info: https://github.com/numpy/numpy/issues/13248

    setup(name='InstantScale',
        version = '0.1',
        description='Parse stuff',
        options = {"build_exe": {"optimize": 1}},
        executables = [Executable("main.py")])
DraXus
  • 81
  • 7