Reputation: 29
Error message from running my exe:
ModuleNotFoundError: No module named 'openpyxl'
testHi.py
#simple test to see if openpyxl module works
import openpyxl
print ("hi")
input()
hook-openpyxl.py
# taken from pyinstaller dev team, store in same dir as testHi.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
cmd line input:
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
I run the the hiTest and get the error above.
I have looked everywhere for this solution. Can anyone tell me what I am doing wrong.
Upvotes: 2
Views: 6291
Reputation: 21
@Kallisto Your answer worked. And command line input of @Gary also worked. Place the file "hook-openpyxl.py" in the folder where your spec file will be created and then use the command line input.
This occurs whenever the hook files for the module we are trying to integrate is missing in "\Lib\site-packages\PyInstaller\hooks".
You can see that there is hook-openpyxl.py between hook-numpy and hook-packaging.
After running the command line input procced with general steps of pyinstaller.
Upvotes: 0
Reputation: 11
You was quite close. :-)
I fixed the problem by modifying the "hook-openpyxl.py" file. The command collect_data_files('openpyxl')
actually returns an empty list. But there is another command collect_submodules
which seems to do what we want. So my "hook-openpyxl.py" file looks like this.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('openpyxl')
I placed the "hook-openpyxl.py" file in the same directory like my spec file. In the spec file I set to location of the new hook file
a = Analysis(
...
...
hookspath=['.'],
...
...
...
I guess, you will have the same result with your command line parameter
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
My environment
Upvotes: 0
Reputation: 31
use --hiddenimport openpyxl
long with the previous solutions, it worked for me, I was able to enforce the import of openpyxl.
Upvotes: 0
Reputation: 720
I was able to get this working using auto-py-to-exe (which uses pyinstaller) by including the following folders/files from my python library into the same folder that I run pyinstaller from:
pyinstaller command:
pyinstaller -y -F "[directory]/myscript.py"
Windows library location for me was: C:\users[username]\AppData\Local\Programs\Python\Python37-32\Lib
The packages were in the "site_packages" folder
Upvotes: 0
Reputation: 31
I fixed my issue by installing it through Pip, rather than install the package through Pycharm, and Pyinstaller was able to find the package.
I got the idea from looking through the text in the command prompt and saw it was loading modules that I had installed via Pip and not through Pycharm.
Upvotes: 3