LoginSignup
6
5

More than 3 years have passed since last update.

【Python】PyInstallerでExe化すると、No module named 'pyproj.datadir' が出るときの対処

Last updated at Posted at 2020-03-17

背景

Pythonファイルをコマンドプロンプト等から起動すると問題なく動いていた。
しかし、PyInstallerでExe化したファイルを実行すると、pyprojをインポートするところで、以下のエラーが送出され、プログラムが落ちてしまった。

ModuleNotFoundError: No module named 'pyproj.datadir'

環境

  • Windows 10
  • Python 3.7.4
  • PyInstaller 3.6
  • pyproj 2.4.0

対処法

specファイル内の、Analysis()のdatasにpyprojのパスを追加するとうまくいった。

.spec
a = Analysis(['hoge.py'],
             pathex=['C:\\workspace\\hoge\\src'],
             binaries=[],
             datas=[
                    ('C:\\Users\\grin\\Anaconda3\\envs\\py_37\\Lib\\site-packages\\pyproj\\*', '.\\pyproj\\'),
                    ],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

追記(2020/08/04)

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\grin\AppData\Local\Temp\_MEI103442\skyfield\data\nutation.npz'

のようなFileNotFoundErrorが出た場合も、該当するファイルパスをdatasに追加すれば大丈夫です。

datas = [('C:\\Users\\grin\\Anaconda3\\envs\\py_37\\Lib\\site-packages\\skyfield\\data\\*', '.\\skyfield\\data\\'),],

参考URL

6
5
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
6
5