2
1

More than 3 years have passed since last update.

Pyinstallerによるpyスクリプトのexe化

Last updated at Posted at 2020-04-25

記事の内容

Pyinstallerを使ってGUIを使うpyスクリプトを実行ファイルにしようとした所、少しハマったのでメモ。

環境

  • Windows10
  • python3.7
  • pyinstaller (pip install pyinstallerでインストール)

現象

pyinstallerでexeファイルを作成したところ以下のようなエラーを吐いた。

Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 13, in <module>
  File "c:\users\username\.virtualenvs\foo_project-uuzswlzx\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pkg_resources\__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[14256] Failed to execute script pyi_rth_pkgres

ぐーぐる先生に聞いて出てくる日本語記事はイマイチなものばかり。
どうやら、pip installでpyinstallerをインストールすると同じ現象が発生するようです。
環境・バージョン依存のバグ??

解決策

pipでインストールしたpyinstallerはアンインストールして、githubからインストールする。

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

さらに同様のエラーが出る場合は、--hidden-importオプションをつける。

pyinstaller --hidden-import pkg_resources.py2_warn example.py
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1