I get error “No module named 'pyproj._datadir'” after I made .py to .exe with pyinstaller

烂漫一生 提交于 2020-07-06 19:29:22

问题


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

Issues with pyinstaller and pyproj

and I was going to try to make and located 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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/55824830/i-get-error-no-module-named-pyproj-datadir-after-i-made-py-to-exe-with-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!