Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

python - In PyInstaller, Why Won't NumPy.Random.Common Load as a Module?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...