Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • 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

like image 803
rdFarinha Avatar asked Nov 18 '25 01:11

rdFarinha


2 Answers

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

like image 135
nouja22 Avatar answered Nov 20 '25 16:11

nouja22


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}}
like image 34
2 revs, 2 users 52%Dr. Strange Avatar answered Nov 20 '25 15:11

2 revs, 2 users 52%Dr. Strange



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!