pyinstallerを使ってexe化したら以下のようなエラーがでた。
pyinstallerの使い方はこちらから
https://camp.trainocate.co.jp/magazine/pyinstaller-python-exe/
PS C:\Users\user\Desktop\chino> .\dist\chino0.exe
Traceback (most recent call last):
File "chino0.py", line 6, in <module>
import sklearn.datasets
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "sklearn\__init__.py", line 82, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "sklearn\base.py", line 17, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "sklearn\utils\__init__.py", line 26, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "sklearn\utils\_joblib.py", line 7, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "joblib\__init__.py", line 113, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "joblib\memory.py", line 32, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "joblib\_store_backends.py", line 15, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "joblib\backports.py", line 22, in <module>
File "_distutils_hack\__init__.py", line 88, in create_module
File "importlib\__init__.py", line 126, in import_module
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "setuptools\__init__.py", line 10, in <module>
File "_distutils_hack\__init__.py", line 88, in create_module
File "importlib\__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'setuptools._distutils'
[10588] Failed to execute script 'chino0' due to unhandled exception!
PyInstallerとscikit-learnの問題かと思い、scikit-learnのバージョンを1.1.2 > 1.0.1 に変えてみたけど治らず。
モジュールの相性かも知れないと思ったのでpip list
で一覧を見てみたら
115もあったので特定ができない。
PS C:\Users\user\Desktop\chino> (pip list | Measure-Object).Count
115
なので大人しくvenvの環境立てて必要なpip installしていったらうまく行った。
https://camp.trainocate.co.jp/magazine/venv-python/
動いたときのpip list
Package Version
------------------------- ---------
altgraph 0.17.3
future 0.18.2
joblib 1.2.0
numpy 1.23.3
pefile 2022.5.30
Pillow 9.2.0
pip 22.0.4
pyinstaller 5.4.1
pyinstaller-hooks-contrib 2022.10
pywin32-ctypes 0.2.0
scikit-learn 1.0.1
scipy 1.9.1
setuptools 58.1.0
threadpoolctl 3.1.0
まとめ
Pythonの開発は必ずvenvを使おう