python - 获取 PyInstaller 导入 Basemap

标签 python pyinstaller matplotlib-basemap

我正在为我构建的使用 basemap 的简单工具构建独立的可执行文件。 (使用Python 2.7,使用PyInstaller的开发版本 - 2.1)。 .exe(单个文件)构建得很好,但是当它运行时,我收到以下错误:

Traceback <most recent call last>:
  File "<string>", line 9, in <module>
  File "c:\python27\lib\site-packages\PyInstaller-2.1dev_-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec<bytecode, module.__dict>
  File "C:\Documents and Settings\MYNAME\Python code\Flood\src\root\nested\build\FloodRisk\out00-PYZ.pyz\mpl_toolkits.basemap", line 30, in <module>
  File "c:\python27\lib\site-packages\PyInstaller-2.1dev_-py2.7.egg\PyInstaller\loader\pyi_importers.py", in load_module
    exec<bytecode, module.__dict__>
  File "C:\Documents and Settings\MYNAME\My Documents\Python code\Flood\src\root\nested\build\FloodRisk\out00-PYZ.pyz\mpl_toolkits.basemap.pyproj", line 242, in <module>
IOError: proj data directory not found. Expecting it at: C:\DOCUME~1\MYNAME\LOCALS~1\Temp\_MEI68362\mpl_toolkits\basemap\data

有人有幸将 basemap 正确加载到使用 PyInstaller 构建的单个 .exe 文件中吗?我正在使用一个非常简单的批处理文件进行构建:

C:\Python27\python.exe "C:\Python27\Lib\site-packages\pyinstaller-develop\PyInstaller\main.py" --onefile "C:\Documents and Settings\MYNAME\My Documents\Python code\Flood\src\root\nested\FloodRisk.py"
pause

谢谢!

最佳答案

花了我几天的时间,但我想我是通过拼凑一些部分解决方案来整理的:

来自http://www.jontrinder.com/blog/?paged=2 :

在 pyproj.py 中,在 C:...\Lib\site-packages\mpl_toolkits\basemap 中找到 就在巨大的列表后面有一行看起来像这样的

pyproj_datadir = os.sep.join([os.path.dirname(__file__), 'data'])

将其替换为

if 'PROJ_DIR' in os.environ:
    pyproj_datadir = os.environ['PROJ_DIR']
else:
    pyproj_datadir = os.sep.join([os.path.dirname(__file__), 'data'])

链接解决方案中缺少的部分是在使用 --paths 实际运行 PyInstaller 时添加数据路径

C:\Python27\python.exe "C:\Python27\Lib\site-packages\pyinstaller-develop\PyInstaller\main.py" --onefile --paths="C:\Python27\Lib\site-packages\mpl_toolkits\*" "C:\Documents and Settings\KAHERE\My Documents\Python code\Flood\src\root\nested\FloodRisk.py"
pause

只是想我会发帖以防其他人在这个问题上大吃一惊。

关于python - 获取 PyInstaller 导入 Basemap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17749296/

相关文章:

python django - 即使在安装编译版本 psycopg2-2.4.5.win32-py2.7.‌exe 之后也没有模块 psycopg2.extension

python - PyInstaller 不会将 PyQt 的图像加载到 GUI

animation - Python matplotlib : animation made of several pyplot. 图-s

python - 属性错误 : 'HTTPHeaderDict' object has no attribute 'get_all' while mapping the mappings in elasticsearch

python - ImportError : No module named. .. 在 __init__.py 文件中

python - Pyinstaller 中的多个隐藏导入

python - Matplotlib Mollweide/Hammer 投影 : region of interest only

python - 在 python basemap 上绘制点会产生运行时错误

python - Pandas:groupby 的问题。错误: 'ValueError: Grouper for <something> not 1-dimensional'

python - 使用 pyinstaller 后执行编译文件 "No module named ' scipy._lib.messagestream' 时出错