Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'scipy.spatial.transform._rotation_groups after compile python script with pyinstaller

After days of looking for an answer on internet and, of course, in overflow I make this post. I hope someone could help me. I made a little program that fits some data that I got from chemistry experimentation with a math model using scipy.optimize. Then I got a plot of the points from the data and the fit. When I run it on the IDLE everything goes okay and when I run from windows command, too. The thing is that a want to make an .exe file so I could share my program with my university classmates. For this I used pyinstaller. When I run pyinstaller to make mi .exe file evertything is ok, but when I want to run it from windows command I get the next output:

Traceback (most recent call last):
  File "solver_tp2fq_ver2.py", line 9, in <module>
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\optimize\__init__.py", line 421, in <module>
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\optimize\_shgo.py", line 9, in <module>
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\spatial\__init__.py", line 107, in <module>
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\spatial\transform\__init__.py", line 19, in <module>
  File "rotation.pyx", line 5, in init scipy.spatial.transform.rotation
ModuleNotFoundError: No module named 'scipy.spatial.transform._rotation_groups'
[10152] Failed to execute script solver_tp2fq_ver2 

As you can see I get the next error: ModuleNotFoundError: No module named 'scipy.spatial.transform._rotation_groups'

I don't understand why I get this error. I installed all the modules, checked that path is correct, upgraded the modules and also reinstalled python (Because this, actually I'm using python 3.9). I don't know what else I can do.

Well, I think it's all. I will be very thankfull if someone helps me.

like image 735
Franco Barrionuevo Avatar asked Jan 07 '21 04:01

Franco Barrionuevo


3 Answers

I've already found and answer in this post: What is the recommended way to persist (pickle) custom sklearn pipelines?

I solved my problem, compiling my python file with the next command:

pyinstaller --hidden-import scipy.spatial.transform._rotation_groups --onefile solver_tp2fq_ver2.py

I'll leave it for someone who maybe have the same problem.

like image 191
Franco Barrionuevo Avatar answered Oct 16 '22 21:10

Franco Barrionuevo


I had exactly the same error. I solved it making some changes into hook-scipy.py and hook-sklearn.metrics.cluster.py (you have to look for them into pyistaller folder) as shown here: scipy import error with pyinstaller

Once the scipy import issue was solved, a sklearn one arised. So, I also had to explicitly add

--hidden-import=sklearn.utils._weight_vector 

while running pyinstaller since previous modifies were not sufficient for my script.

like image 2
FrancisSem Avatar answered Oct 16 '22 19:10

FrancisSem


I solved exactly the same issue (Issue with cx_Freeze) just by putting import scipy.spatial.transform._rotation_groups in the top of my main.py file. Probably not a clean solution though...

like image 2
Hmatt Avatar answered Oct 16 '22 19:10

Hmatt