问题描述
当我的代码为.py时,效果很好但是当我使用pyinstaller制作.exe文件时,它显示了ModuleNotFoundError.
My code works well when it's .pybut when I make .exe file with pyinstaller, it shows ModuleNotFoundError.
我在制作.exe时写了这个
I write this when I made .exe
pyinstaller -F MyCode.py
我该如何解决这个问题?
How can I solve this problem?
我读过
,我打算在Pyinstaller的"hooks"文件夹中创建hook-pyproj.py并将其定位.但是hook-pyproj.py已经在那里有相同的代码.
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.
之后,我安装了底图",并尝试从中使用pyproj.但是,它向我显示了相同的错误.
After that, I installed "basemap" and tried to use pyproj from it. However it shows me the same error.
这是我执行.exe文件时向我显示的错误.(我用*****涵盖了一些信息)
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
这是我的代码.
from mpl_toolkits.basemap import pyproj as pyproj
我一开始尝试过.
import pyproj
但是我得到相同的"ModuleNotFoundError:没有名为'pyproj._datadir'的模块"错误.
but I get same " ModuleNotFoundError: No module named 'pyproj._datadir' " error.
推荐答案
有点奇怪,我不完全理解为什么,但是找到了一个快速的肮脏修复程序.您可以添加此导入
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
到您现有的.
这篇关于我收到错误“没有名为'pyproj._datadir'的模块"在我用pyinstaller将.py转换为.exe之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!