PyInstaller with Pandas creates over 500 MB exe
PyInstaller creates a big executable from conda packages and a small executable from pip packages. From this simple python code:
from pandas import DataFrame as df
print('h')
I obtain a 203MB executable using conda packages and a 30MB executable using pip packages. But conda is a nice replacement for pure virtualenv. I can develop with conda and Jupyter, create some script 'mycode.py' (I can download Jupyter notebook as py-file in myfolder).
But my final solution is next: If you do not have it, install Miniconda and from the Windows Start Menu open Anaconda Prompt;
cd myfolder
conda create -n exe python=3
activate exe
pip install pandas pyinstaller pypiwin32
echo hiddenimports = ['pandas._libs.tslibs.timedeltas'] > %CONDA_PREFIX%\Lib\site-packages\PyInstaller\hooks\hook-pandas.py
pyinstaller -F mycode.py
Where I create a new environment 'exe', pypiwin32 is needed for pyinstaller but is not installed automaticaly, and hook-pandas.py is needed to compile with pandas. Also, importing submodules does not help me optimize the size of the executable file. So I do not need this thing:
from pandas import DataFrame as df
but I can just use the usual code:
import pandas as pd
Also, some errors are possible along using the national letters in paths, so it is nice the english user account for development tools.
pandas to_excel not working with pyinstaller
As the pandas
documentation specifies, in order for to_excel
and read_excel
methods to work you have to install one or more of the following packages alongside pandas
:
XLsxWriter 0.9.8 Excel writing
openpyxl 2.5.7 Reading / writing for xlsx files
pyxlsb 1.0.6 Reading for xlsb files
xlrd 1.1.0 Excel reading
xlwt 1.2.0 Excel writing
Depending on your setup you might have not installed them or you might have not included them in pyinstaller
list of packages.
Pyinstaller one file works in python shell but fails as an exe
with the pyinstaller one file executable you will often ran into problems like that. When starting the *.exe it is extracted to a temporary directory and this is for example the start-location for relative path definitions.
So even if you get your script running and export your *.csv it will often be somewhere on your HD and not at the place of the *.exe where you perhaps expect it to be.
I think in your case the variable df_list stays empty because there are no files listed in csv_files. This is because in the temp dir (location is written in the top of the output) there are no *.csv files.
Please try printing the content of csv_files when running the one-file *.exe if this is the right guess
If this is the case start by running a one-dir *.exe and if this works you know that you have a problem with your path definitions
PyInstaller Executable File: ModuleNotFoundError - Pandas
Try using this commandline for compiling your python file, pyinstaller.exe --onefile --noconsole --hidden-import pandas {Your_FILE_NAME}.py
Related Topics
Type Hints with User Defined Classes
How to Replace (Or Strip) an Extension from a Filename in Python
Python Argparse Ignore Unrecognised Arguments
Cannot List Ftp Directory Using Ftplib - But Ftp Client Works
Python: Sorting Items from Top Left to Bottom Right with Opencv
How Can a Recursive Regexp Be Implemented in Python
Pandas: Convert Dtype 'Object' to Int
How to Loop Through a List by Twos
Set Up Python 3 Build System with Sublime Text 3
Select Multiple Ranges of Columns in Pandas Dataframe
Accessing the List While Being Sorted
Can Multiprocessing Process Class Be Run from Idle
Minimum Euclidean Distance Between Points in Two Different Numpy Arrays, Not Within
How to Print Utf-8 Encoded Text to the Console in Python < 3