I get error "No module named 'pyproj._datadir'" after I made .py to .exe with pyinstaller [duplicate]
Asked Answered
B

2

5

My code works well when it's .py but when I make .exe file with pyinstaller, it shows ModuleNotFoundError.

I write this when I made .exe

pyinstaller -F MyCode.py

How can I solve this problem?

I've read some solutions from Issues with pyinstaller and pyproj so I was going to try to make and locate hook-pyproj.py at "hooks" folder in Pyinstaller. but hook-pyproj.py was already there with the same code.

After that, I installed "basemap" and tried to use pyproj from it. However it shows me the same error.

This is the error it showed me when I execute the .exe file. (I covered some information with *****)

Traceback (most recent call last):
  File "collect\MyCode.py", line 8, in <module>
  File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\mpl_toolkits\basemap\__init__.py", line 41, in <module>
  File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pyproj\__init__.py", line 62, in <module>
  File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pyproj\crs.py", line 26, in <module>
  File "pyproj\_crs.pyx", line 1, in init pyproj._crs
ModuleNotFoundError: No module named 'pyproj._datadir'
[25936] Failed to execute script MyCode

This is my code.

from mpl_toolkits.basemap import pyproj as pyproj

I tried this at first.

import pyproj

but I get same " ModuleNotFoundError: No module named 'pyproj._datadir' " error.

Baccalaureate answered 24/4, 2019 at 7:45 Comment(0)
B
6

It's a bit odd and I don't exactly understand why but I found a quick dirty fix. You can add this import

from pyproj import _datadir, datadir

to your existing one.

Ballast answered 24/4, 2019 at 22:52 Comment(1)
This PR attempts to fix the issue in PyInstaller: github.com/pyinstaller/pyinstaller/pull/4803Malan
L
0

I noticed this pyproj import dll error error occurred on some Windows machines and not others.

Turned out to be a dependency on Visual C Runtime 2015+

https://support.microsoft.com/en-au/help/2977003/the-latest-supported-visual-c-downloads

Lancelle answered 29/11, 2019 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.