scipy import error with pyinstaller

2024/10/14 7:19:25

I am trying to build a "One File" executable for my project with pyinstaller and a .spec file. The content of the spec file is as follows:

# -*- mode: python -*-block_cipher = Nonea = Analysis(['__main__.py'],pathex=['D:\\opt_frame'],binaries=[],datas=[],hiddenimports=['scipy.special', 'scipy.special.comb'],hookspath=[],runtime_hooks=[],excludes=[],win_no_prefer_redirects=False,win_private_assemblies=False,cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,cipher=block_cipher)
exe = EXE(pyz,a.scripts,exclude_binaries=True,name='__main__',debug=False,strip=False,upx=True,console=True )
coll = COLLECT(exe,a.binaries,a.zipfiles,a.datas,strip=False,upx=True,name='__main__')

I am getting the following error when I am trying to run the executable:

File "site-packages\scipy\special\__init__.py", line 640, in <module>File "d:\opt_frame\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_modulemodule = loader.load_module(fullname)
ImportError: DLL load failed: The specified module could not be found.

It fails when trying to import scipy.special even though I have added it to hiddenimports section.

My environment is as follows:

  • Windows 10
  • python 3.6.6
  • pyinstaller 3.3.1
  • scipy 1.1.0
Answer

I had the exact same problem and I found a solution in another thread, (How do you resolve 'hidden imports not found!' warnings in pyinstaller for scipy?)

I made the hook-scipy.py file that Chris's answer suggested with the exact same code:

    from PyInstaller.utils.hooks import collect_submodulesfrom PyInstaller.utils.hooks import collect_data_fileshiddenimports = collect_submodules('scipy')datas = collect_data_files('scipy')

Worked like a charm! Hope this helps you as well.

https://en.xdnf.cn/q/117983.html

Related Q&A

How to compare meaningful level of a set of phrase that describe same concept in NLP?

I have two terms "vehicle" and "motor vehicle". Are there any way to compare the meaningfulness level or ambiguity level of these two in NLP? The outcome should be that "motor…

TypeError: slice indices must be integers or None or have an __index__ method. How to resolve it?

if w<h:normalized_char = np.ones((h, h), dtype=uint8)start = (h-w)/2normalized_char[:, start:start+w] = charelse:normalized_char = np.ones((w, w), dtype=uint8)start = (w-h)/2normalized_char[start:st…

Keras: Understanding the number of trainable LSTM parameters

I have run a Keras LSTM demo containing the following code (after line 166):m = 1 model=Sequential() dim_in = m dim_out = m nb_units = 10model.add(LSTM(input_shape=(None, dim_in),return_sequences=True,…

Updating Labels in Tkinter with for loop

So Im trying to print items in a list dynamically on 10 tkinter Labels using a for loop. Currently I have the following code:labe11 = StringVar() list2_placer = 0 list1_placer = 1 mover = 227 for items…

Paginate results, offset and limit

If I am developing a web service for retrieving some album names of certain artist using an API, and I am asked:The service should give the possibility to paginate results. It should support ofset= and…

Improve code to find prime numbers

I wrote this python code about 3 days ago, and I am stuck here, I think it could be better, but I dont know how to improve it. Can you guys please help me?# Function def is_prime(n):if n == 2 or n == …

How to read the line that contains a string then extract this line without this string

I have a file .txt that contains a specific line, like thisfile.txt. . T - Python and Matplotlib Essentials for Scientists and Engineers . A - Wood, M.A. . . .I would like to extract lines that contain…

Python: How to access and iterate over a list of div class element using (BeautifulSoup)

Im parsing data about car production with BeautifulSoup (see also my first question):from bs4 import BeautifulSoup import stringhtml = """ <h4>Production Capacity (year)</h4>…

What should I worry about Python template engines and web frameworks? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argum…

Value Search from Dictionary via User Input

I have written the following code for getting an output of the various districts located in the given city and their respective postal codes. I want my code to be able to receive input from the user (D…