4

I'm trying to create an executable from a Python script using PyInstaller, but I get the following error:

30391 INFO: Loading module hook "hook-distutils.py"...
Unable to find "\AppData\Local\Programs\Thonny\Include\pyconfig.h" when 
adding binary and data files.

I could only find instances of people having this problem on Linux, but I'm on Windows. I tried adding an empty file called pyconfig.h to the given file path. This allowed PyInstaller to complete, but the resulting .exe file only prints some text and immediately closes the console window.

I successfully created an executable from another script that uses all the same packages aside from pandas, so I believe that might be the problem.

I'm running PyInstaller through the system shell on Thonny. My OS is Windows 10 and my Python version is 3.6.4.

Sam S
  • 51
  • 1
  • 5

2 Answers2

1

Alright, so I managed to solve this by myself. Turns out it was a combination of several errors.

Creating an empty pyconfig.h file did solve the original problem.

Running the exe from the command line allowed me to see what the actual issue was. Turns out it was a missing hidden import from the pandas module.

I also forgot to include my data file and Chrome driver. All of these problems were fixed my editing the pyinstaller spec file:

a = Analysis(['script.py'],
         binaries=[('chromedriver.exe','.')],
         datas=[('data/datafile.xlsx','data')],
         hiddenimports=['pandas._libs.tslibs.timedeltas'],
         ...)
Sam S
  • 51
  • 1
  • 5
1

pyconfig.h is part of the python-dev package. Installing python-dev can also fix your issue.

See this question to understand more about what python-dev is: What is python-dev package used for

congusbongus
  • 13,359
  • 7
  • 71
  • 99
  • What I have done is yank a similar pyconfig.h file from an installed Python. [Not the best practice...] – Jiminion Jul 17 '18 at 16:40