获取PyInstaller导入底图 [英] Get PyInstaller to import Basemap

查看:210
本文介绍了获取PyInstaller导入底图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on building a standalone executable for a simple tool I built that uses Basemap. (Using Python 2.7, using the dev version of PyInstaller - 2.1). The .exe (single file) builds just fine, but when it runs, I get the following error:

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文件中吗?我正在使用一个非常简单的批处理文件进行构建:

Anyone have any luck getting Basemap to load properly into a single .exe file built using PyInstaller? I'm building using a very simple batch file:

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

谢谢!

推荐答案

花了几天时间,但我认为我将一些部分解决方案拼凑而成:

Took me a few days, but I think I sorted it from piecing together a few partial solutions:

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

在pyproj.py中,位于C:... \ Lib \ site-packages \ mpl_toolkits \ basemap中 在巨大的列表之后是​​一条看起来像

In pyproj.py, found in C:...\Lib\site-packages\mpl_toolkits\basemap Just past the huge lists is a line that looks something like

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时添加数据路径

The piece that was missing from the linked solution was then adding the data path when actually running PyInstaller with --paths

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

只是以为我会发帖,以防其他任何人在此上面敲头.

Just thought I'd post in case anyone else was banging their head on this one.

这篇关于获取PyInstaller导入底图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆