7

I'm trying to compile a .py program into a Windows .exe using PyInstaller. Whenever I try to execute the .exe, the terminal opens, then closes quickly with the error:

ImportError: Unable to import required dependencies: numpy: No module named 'numpy.random.common'

I'm not explicitly importing numpy; it's being import by pandas.

I also get this long list of warnings about modules that couldn't be loaded in the warnings log for pyinstaller.

I've tried adding hiddenimports=['numpy.random.common'] in my .spec file, I've tried running `pyinstaller [file].py -F --hidden-import="numpy.random.common". I've read the other stackoverflow posts about pyinstaller and hiddenimports, yet nothing seems to fix this error.

I'm using a virtual environment, so I'm not sure if that's playing a part.

Here's my .spec file

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

block_cipher = None

a = Analysis(['getNewPropertiesLabels.py'],
             pathex=['C:\\Users\\[user name]\\OneDrive\\Documents\\Consulting\\[file name]'],
             binaries=[],
             datas=[],
             hiddenimports=['numpy.random.common'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='Name',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True')

My warning file causes the post to be too long, however numpy.random.common isn't actually listed as a missing module. Neither is numpy.random.

I'm expecting this to just run properly without any issues.

Tracey
  • 71
  • 1
  • 1
  • 2

7 Answers7

11

Solved this by adding three imports before import pandas.

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

It seems that PyInstaller loses the path to these libraries... Then, at the command line I wrote:

pyinstaller install -n APP_NAME -c --clean SCRIPT_NAME.py

and it worked for me.

B--rian
  • 5,578
  • 10
  • 38
  • 89
Dave
  • 111
  • 2
  • 1
    If the above doesn't work, adding --hidden-import="numpy.random.common" --hidden-import="numpy.random.bounded_integers" --hidden-import="numpy.random.entropy" to the build may work – user2370125 Aug 13 '19 at 14:17
6

I could fix it downgrading numpy from 1.17.0 to 1.16.2. In the attached image you can see the related pandas, numpy and rest of the packages I've used.

pip uninstall numpy
pip install numpy==1.16.2

Packages used

Anibal
  • 61
  • 1
1

In my environment with numpy==1.16.1 and pandas==0.24.1 I do not have numpy.random.common

If you try to import it from python console it works?

Maybe try to upgrade/downgrade pandas (pip install pandas==0.24.1).

Grzegorz Bokota
  • 1,736
  • 11
  • 19
0

I've been struggling with the same problem just yesterday. At first I had a problem with ssl module and then with numpy.random, as well a list of other modules not loaded correctly...

Please look at my question here and I've listed a number of things I've done to try and solve this problem in the following answer.

Let me know if the problem is solved by this measures, cause I wasn't able to pinpoint the exact step that solved it. (I believe it is a combination of all).

Tim Mironov
  • 849
  • 8
  • 22
0

I have the same problem which I'm trying to solve for hours! this trick didn't work for me although I recommend trying it, downgrading numpy and pandas solved the "import numpy problem" caused by pandas disappear.. only because now it can't find pandas! (although I specified pandas under hiddenimports)

L.S
  • 81
  • 6
0

Adding 'numpy.random.common', 'numpy.random.bounded_integers' and 'numpy.random.entropy' to my hidden imports worked for me.

Ctrd00
  • 43
  • 5
0

the problem that i got was numpy was not installed

after installing numpy it worked

pip install numpy
Abi Chhetri
  • 1,131
  • 10
  • 15