前提・実現したいこと
Python3.6のsklearnを使用して簡単な重回帰分析を行うプログラムをexeで動かしたい。
発生している問題・エラーメッセージ
Python
1Traceback (most recent call last): 2 File "SimplePred01.py", line 3, in <module> 3 import sklearn 4 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 5 line 631, in exec_module 6 exec(bytecode, module.__dict__) 7 File "lib\site-packages\sklearn\__init__.py", line 134, in <module> 8 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 9 line 631, in exec_module 10 exec(bytecode, module.__dict__) 11 File "lib\site-packages\sklearn\base.py", line 13, in <module> 12 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 13 line 631, in exec_module 14 exec(bytecode, module.__dict__) 15 File "lib\site-packages\sklearn\utils\__init__.py", line 11, in <module> 16 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 17 line 631, in exec_module 18 exec(bytecode, module.__dict__) 19 File "lib\site-packages\sklearn\utils\validation.py", line 18, in <module> 20 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 21 line 631, in exec_module 22 exec(bytecode, module.__dict__) 23 File "lib\site-packages\sklearn\utils\fixes.py", line 144, in <module> 24 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 25 line 631, in exec_module 26 exec(bytecode, module.__dict__) 27 File "lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in <module 28> 29 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 30 line 631, in exec_module 31 exec(bytecode, module.__dict__) 32 File "lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <m 33odule> 34 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 35 line 631, in exec_module 36 exec(bytecode, module.__dict__) 37 File "lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in < 38module> 39 File "c:\venv\ins\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", 40 line 714, in load_module 41 module = loader.load_module(fullname) 42ImportError: DLL load failed: 指定されたモジュールが見つかりません。 43[11720] Failed to execute script SimplePred01
該当のソースコード
Pyinstallerでexe化するときに使用したspecファイルの中身。
他ブログ等を参考にして、pandasは読み込んだが、sklearnを読み込んでいないっぽい。
Python
1# -*- mode: python -*- 2 3block_cipher = None 4 5himports = [ 6 'pandas', 'sklearn'] 7 8def get_pandas_path(): 9 import pandas 10 pandas_path = pandas.__path__[0] 11 return pandas_path 12 13def get_sklearn_path(): 14 import sklearn 15 sklearn_path = sklearn.__path__[0] 16 return sklearn_path 17 18a = Analysis(['SimplePred01.py'], 19 pathex=['C:\Users\z05464p0\Python\F_test02\make_exe'], 20 binaries=[], 21 datas=[], 22 hiddenimports=[], 23 hookspath=[], 24 runtime_hooks=[], 25 excludes=[], 26 win_no_prefer_redirects=False, 27 win_private_assemblies=False, 28 cipher=block_cipher) 29 30dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"]) 31a.datas += dict_tree 32a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries) 33 34 35dict_tree = Tree(get_sklearn_path(), prefix='sklearn', excludes=["*.pyc"]) 36a.datas += dict_tree 37a.binaries = filter(lambda x: 'sklearn' not in x[0], a.binaries) 38 39pyz = PYZ(a.pure, a.zipped_data, 40 cipher=block_cipher) 41exe = EXE(pyz, 42 a.scripts, 43 exclude_binaries=True, 44 name='SimplePred01', 45 debug=False, 46 strip=False, 47 upx=True, 48 console=True ) 49coll = COLLECT(exe, 50 a.binaries, 51 a.zipfiles, 52 a.datas, 53 strip=False, 54 upx=True, 55 name='SimplePred01')
試したこと
- venv仮想環境で最低限のモジュールでexe化。
- .specに
himports = ['pandas', 'sklearn']
を追加。 - .specに
get_pandas_path()
などを追加。pandasは読み込まれるようになった。 - .specに
get_sklearn_path()
などを追加。sklearnは読み込まなかった。
補足情報(FW/ツールのバージョンなど)
上記を参考にソースコードとエラーコードはで``` ```囲ってもらえますか
ご指摘ありがとうございます。Markdownを使用しました。
回答2件
あなたの回答
tips
プレビュー