How to package pandas, with pyinstaller and avoid some common mistakes

< H2 > question < / H2 >

I want to use pandas to generate a DataFrame input .csv file, but the packaged .exe file cannot be implemented after running.

< H2 > 1. Environment < / H2 >
  • Win10
  • Python3.6.4 (the latest version of Anaconda)
  • PyInstaller: 3.3.1

Code to be packaged ( amyfile.py )

import pandas as pd
import numpy as np
arr1 = np.arange(100).reshape(10,10)
data1 = pd.DataFrame(arr1)
data1.to_csv(r"D:\b.csv",index=False,header=False,decimal=",") 

the first pit, the error is as follows

"utf-8" codec can"t decode byte 0xce in position 122: invalid continuation....

solution: enter

in CMD
CHCP 65001
< H2 > 2. Tried method < / H2 >

(1) the first method

my younger brother has been Baidu many times before, including adding

to amyfile.spec .
def get_pandas_path():
    import pandas
    pandas_path = pandas.__path__[0]
    return pandas_path
 

dict_tree = Tree(get_pandas_path(), prefix="pandas", excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: "pandas" not in x[0], a.binaries)

Link: [organize] PyInstaller packages for programs containing Python3.4, PyQt, Pandas, Multiprocess

in addition

(2) the second method

I need to go to GitHub to find a host file. I don"t know anything about host. I don"t know how to get the address given by the author. I don"t know where to put it. I wonder if it really works?
python-jiao-ben-de-yi-xie-xin-de/" rel=" nofollow noreferrer "> some experiences of PYINSTALLER packaging PYTHON script

< H2 > 3. Pandas and Numpy libraries are just missing in the packaged file < / H2 >

looked carefully at the warnamyfile.txt in the build file and found that none of the modules were imported, and all the libraries generated in dist were libraries I didn"t need.

Mar.01,2021
Menu