[Pyinstaller]: Working Code Produces ModuleNotFoundError When Turned To Exe

- 1 answer

Working with Pyinstaller 3.5 and python 3.6 (installed with Anaconda).

I have a python code that explicitly imports numpy and works fine when launched with Spyder or the Anaconda prompt.

Using pyinstaller to produce an exe in the Anaconda prompt, it generates fine without any error.

However, when launching the exe (still from the Anaconda prompt), it produces the following error : ModuleNotFoundError: No module named 'numpy'

I checked that numpy was correctly installed with Anaconda. I also installed it again with: pip install numpy and regenerated the exe without success (more of a despair move).

I also tried -hidden-import=numpy but it did not work. Still the same error.

Do you guys have any idea why this does not work ?

I made a shorter piece of code to test the issue:

# import all the libraries required
import os, re, time, csv, math

import numpy as np
import matplotlib
import matplotlib.figure
import matplotlib.backends.backend_tkagg
import matplotlib.patches
import matplotlib.gridspec
import itertools

from tkinter import filedialog
from tkinter import messagebox

import tkinter
import tkinter.constants as const
from tkinter import ttk

import xlrd # Read Xls files

# Compute the used colors
colors = {  "white":        [ 255,255,255],
            "lightgreen":   [ 192,255,192],
            "red":          [ 255, 64, 64],
            "grey":         [ 224,224,224],
            "darkgrey":     [  64, 64, 64],
            "green":        [   0,255,  0],
            "blue":         [ 150,150,255],
            "orange":       [ 255,190,  0],
color0 = colors["red"]
color1 = colors["lightgreen"]
colorMap = np.array([color0, color1], dtype = np.uint8)


The solution to the problem was to run Anaconda as Admin to install pyinstaller through Anaconda. In the shortcut menu, right click on Anaconda and run as Admin. Then, installing new modules is possible. Install pyinstaller. Run pyinstaller in Anaconda prompt.

The ModuleNotFoundError disappeared and the exe runs fine when launched from Anaconda prompt.

Still does not work when launched from finder though it's another problem.