4
votes

Summary

I just wrote a Python (3.7.2) program and an using Pyinstaller (3.4) to compile it to an exe. The Python file is using opencv-python (which required numpy) as a dependency. Despite having looked for a while, none of the solutions I have seen online have worked for me.

I do not have anaconda installed, not do I have multiple versions of any of the libs I am using (including Python itself).

Also, when I run 'from numpy import multiarray' in python, even that prints out an error that it cannot do the import.

What I have tried

unistalling and reinstalling numpy and opencv-python

updating numpy to the latest version (1.16).

Running pyinstaller on the program in Windows 10 and 7 VMs in addition to my native Windows 10 (with all dependencies installed prior via pip, of course) (A quick note--when I ran on Win7 I did not get any of the 'lib not found:' errors that I saw in Win10, but the program still failed to run)

None of these results made a difference in the error message I received that 'numpy.core.multiarray failed to import'.

The question

How do I get my program to compile to an exe? I'm open to using a different program (other than pyinstaller).

Thank you!!

The data I have

Here is the error message from running 'from numpy import multiarray' in a python terminal:

ImportError: cannot import name 'multiarray' from 'numpy' (C:\Users\name\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\__init__.py)

Here is the full error message from attempting to run the compiled exe

PS C:\Users\name\Downloads\py\dist\SignRecorder> .\SignRecorder.exe
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "SignRecorder.py", line 1, in <module>
File "c:\users\name\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cv2\__init__.py", line 3, in <module>
ImportError: numpy.core.multiarray failed to import
[15208] Failed to execute script SignRecorder

Here is the final build output from pyinstaller

C:\Users\name\Downloads\py\build\SignRecorder\SignRecorder.exe
19881 INFO: Building EXE from EXE-00.toc completed successfully.
19893 INFO: checking COLLECT
19893 INFO: Building COLLECT because COLLECT-00.toc is non existent
19894 INFO: Building COLLECT COLLECT-00.toc
28366 INFO: Building COLLECT COLLECT-00.toc completed successfully.
1
It is quite possible that you have another version of numpy installed somewhere on your computer that is causing this problem. You might want to check that. Or you could try uninstalling the version you have and then installing a version below the latest available.Rick M.
How would I check for that? I tried running 'pip list' and it only showed one numpy version. Also, running 'pip uninistall numpy' multiple times only removes numpy once, so I do not know where my other numpys would be.Jeffrey - Siothrún as Gaeilge
Did you use a virtual environnent ? It may solve your issue if you run pyinstaller in this isolated and controled env.Dorian Turba
I did not use a virtual environment. I can try using venv and see it it helps later todayJeffrey - Siothrún as Gaeilge
I used venv to create a virtual environment and still got the same error: (I did remember to activate the environment) Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'multiarray' from 'numpy' (C:\Users\name\Documents\Standard Documents\Programming\Environments\SignRecorderEnvironment\lib\site-packages\numpy_init_.py)Jeffrey - Siothrún as Gaeilge

1 Answers

2
votes

Thanks to Rick M, I was able to find out that my versions were too recent and did not work well with each other. The configuration I used that worked was:

Python 3.5 or 3.7.2 (latest as of 01 / 23 / 2019)

Pyinstaller 3.4

numpy 1.15