3

exe file starts but crashes with ModuleNotFoundError: No module named 'numpy.random.common'

I use pyinstaller --onefile hello.py --hidden-import pandas and .exe file fails. I've tried to change the spec file with adding path to pandas , but the .exe file still fails.

Contents of hello.py file:

import os
input("before loading pandas")
import pandas
print ("hello")
input('waiting for keyboard input')

Contents of spec file:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

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


a = Analysis(['CreateExcelSAList.py'],
             pathex=['D:\\OneDrive - Ardovlam NV\\15. Python\\hello'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
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)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='hello',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )
scoll=COLLECT(exe,
            a.binaries,
            a.zipfiles,
            a.datas,
            strip=None,
            upx=True,
            name='hello')
viddik13
  • 5,930
  • 2
  • 14
  • 21

2 Answers2

0

seems to be a known error. Please check: https://github.com/numpy/numpy/issues/14163. There is a reference to a solution in stackoverflow.

jAguesses
  • 91
  • 5
0

i've got the solution, found here In PyInstaller, Why Won't NumPy.Random.Common Load as a Module?

i've imported things below just before importing pandas in my hello.py

import numpy.random.common
import numpy.random.bounded_integers
import numpy.random.entropy

After running pyinstaller hello.py, my exe file was running as expected

in another program it was not enough to import the numpy libs, i've got to change also xx.spec file with 'hiddenimports'

hiddenimports=['numpy.random.common','numpy.random.entropy','numpy.random.bounded_integers'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
         noarchive=False)