[Pyinstaller]: Working Code Produces ModuleNotFoundError When Turned To Exe
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)
Answer
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.
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module