PyInstaller: ImportError: cannot import name 'ccompiler' from partially initialized module 'numpy.distutils'

Viewed 436

After freezing my program with PyInstaller, I encountered following error while trying to run the executable:

ModuleNotFoundError: No module named 'numpy.distutils'

After adding numpy.distutils to hidden imports, I am getting a new error:

ImportError: cannot import name 'ccompiler' from partially initialized module 'numpy.distutils' (most likely due to a circular import)

with which I don't know what to do. Those are imports from my code :

import pyodbc
import numpy as np
import fiona
import pandas as pd
import geopandas as gpd
import rasterio
from rasterio import features
from rasterstats import zonal_stats
import PySimpleGUI as sg
2 Answers

Try to collect all submodules of Numpy

--collect-submodules numpy

then, you may get a new error or others

ModuleNotFoundError: No module named 'distutils.unixccompiler'

Adding them to hidden imports

--hidden-import distutils.unixccompiler

Just update to Pyinstaller 4.8. They fix this error in this release.

Related