rdFarinha
rdFarinha

Reputation: 41

cx_freeze - ImportError: numpy.core.multiarray failed to import

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:

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

Upvotes: 3

Views: 3296

Answers (3)

DraXus
DraXus

Reputation: 81

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")])

Upvotes: 1

Xantium
Xantium

Reputation: 11603

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}}

Upvotes: 1

nouja22
nouja22

Reputation: 11

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

Upvotes: 1

Related Questions