Pyinstllerパッケージexeエラー解決


前言
  • pythonで自動化ツールを書き、python環境のない同僚が使いやすいようにexeにパッケージするつもりです.
  • 本人が仮想環境を使用しているため、デフォルトの仮想環境ではpyinstallerがなく、コードを書いたパソコンにはネットワークがないため、パッケージをローカルにインストールするしかありません.

  • インストール
  • より前の項目はpython 2である.7、pyinstallerをインストールする場合、以下のような依存ライブラリをインストールする必要があります.-altgraph-dis 3-future-macholib-pefile-pywin 32-ctypes
  • dis 3とfutureはいずれもpython 2のため、一部のpython 3の特徴をインポートする必要がある.pyinstallerのドキュメントを読むとpyinstaller 3がわかります.4 pywin 32への依存は完全に停止し、pywin 32-ctypeに依存した.

  • に質問
    パッケージングに成功した後、ファイルはTraceback (most recent call last): File “PyInstaller/loader/rthooks/pyi_rth__tkinter.py”, line 28, in FileNotFoundError: Tcl data directory “/var/folders/nl/2wxh3z313l129zpzq2f8ww5m0000gn/T/_MEILUmJRc/tcl” not found. [2195] Failed to execute script pyi_rth__tkinterを間違えました.
    最初は仮想環境の問題だと思って、長い間調べていました.最後に、様々な外部ネットワークを調べて、原因は以下の通りです.
    The Error Message basically refers to a file that cannot be found. In most cases, this file may not be necessary to run your application. The only way to know it is to refer to the file pyi_rth_tkinter.py
    The file pyi_rth_tkinter.py can be found under the venv folder of your project.
    venv/lib/python3.7/site-packages/PyInstaller/loader/rthooks/pyi_rth_tkinter.py
    You will find a simple IF Statement that returns an error if a specific file is not found in the tk or tcl directory. You can comment the IF Statement as provided below and try running your PyInstaller code once again
    これらの行のコードを注釈します(不思議な解決方法です.)
    #if not os.path.isdir(tcldir):
        #raise FileNotFoundError('Tcl data directory "%s" not found.' % (tcldir))
    #if not os.path.isdir(tkdir):
        #raise FileNotFoundError('Tk data directory "%s" not found.' % (tkdir))
    

    最終的に生成されたexeは正常に実行されました~