1

I'm trying to run a python script compiled into a .exe with pyinstaller and I'm running into issues when importing scipy (no issues with other imported packages) :

Traceback (most recent call last):
  File "Sim_choix_modal.py", line 15 in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\yimode03_importers.py", line 495, in exec_module
  File "scipy\__init__.py, line 76 in <module>
  File "scipy\__init__.py, line 67 in _delvewheel_init_patch_1_1_0
  File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable: 'C:\\Users\\username~1\\AppData\\Local\\Temp\\_MEI155082\\scipy.libs'
[17952] Failed to execute script 'Sim_choix_modal' due to unhandled exception!

Some intel :

  • The python script is named 'Sim_choix_modal.py'
  • The line 15 in Sim_choix_modal.py is import scipy
  • The french text after [WinError 2] is equivalent to "No such file or directory: 'C:\Users\...".
  • To compile my python script I use the command pyinstaller --onefile Sim_choix_modal.py

I've read similar questions and tried stuff that seemed to work for other users :

  1. Adding the option --add-data "path/to/venv/Lib/site-packages/scipy.libs;scipy.libs/" when compiling the .py into a .exe, make the .exe close (crash?) when run, without displaying any error (source : PyInstaller FileNotFoundError "scipy.libs")

  2. Add hiddenimports=['scipy._lib.messagestream'] into the spec file (tried before and after compiling the .py into .exe : doesn't seems to change anything, same error message. (source : Error when executing compiled file " No module named 'scipy._lib.messagestream' "after using pyinstaller)

  3. Followed this reply, to no avail : https://stackoverflow.com/a/62238104/22319153 (which if I understood correctly is supposed to add a hook for scipy to pyinstaller)

Thanks in advance for your time,

Paul

BDL
  • 21,052
  • 22
  • 49
  • 55
P.Bryss
  • 11
  • 2

1 Answers1

0

I managed to make it work, although I'm not quite sure what did the trick.

  1. I've updated scipy
  2. based on this post (https://stackoverflow.com/a/47979807/22319153) I removed the --onefile option when compiling then copied the content of the scipy directory (where it is installed) into the other scipy directory (in the exectuable directory)
  3. based on this post (https://stackoverflow.com/a/47979807/22319153), in the .spec file, I filled in the Data = [...] in a = Analysis (replacing 'plotly' with 'scipy' and adding another element to Data for 'scipy.libs'
P.Bryss
  • 11
  • 2