I had exactly the same problem, and I found another solution (the only one that worked for me actually) :
I followed pretty much this : https://medium.com/@liron92/pyinstaller-with-pandas-problems-solutions-and-workflow-with-code-examples-c72973e1e23f
Except for the fact that I run my virtual environnement on Anaconda.
Quick step-by-step sollution
Before I start : these are the steps that I followed for my particuliar case, you might want to adapt a little bit depending on your situation.
1) Create and configure your virtual environnement
I used Anaconda to create my env :
conda create --name myenv
Then I installed all the module I needed :
conda install -n myenv pandas
conda install -n myenv -c conda-forge python-docx
etc.
2) Activate your environnement and switch to project path
On Anaconda Prompt :
conda activate myenv
cd path/to/your/project/folder
3) Create and modify your *.spec file
Still on the same Anaconda Prompt window :
pyi-makespec project.py
Then open your project.spec file, it will looks like that:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['project.py'],
pathex=['path/to/your/project/folder'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')
You just modify hiddenimports = []
and add all the implicit import (which include pandas).
In my case, I was also using Tkinter, so I specified :
hiddenimports=['pandas', 'tkinter']
4) Finally run pyinstaller
On the same Anaconda Prompt window (environnement activated, on your project directory) :
pyinstaller main.spec
And then you're done !
Disclaimer
I see everywhere people telling you that you should use --onefile
when you compile a Python project with Pyinstaller, I honestly think you shouldn't : it makes the *.exe way slower. Maybe I'm missing something with this so please if you use it explain to me.
Specs
Windows 10
Anaconda 4.8.2
Python 3.7.6
Pandas 1.0.5