我正在为我构建的使用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
谢谢!
答案 0 :(得分:1)
我花了几天时间,但我想我是通过拼凑几个部分解决方案来分类的:
来自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'])
链接解决方案中缺少的部分然后在实际运行PyInstaller时使用--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
以为我会发帖,以防其他人正在敲打这个。
答案 1 :(得分:0)
您需要做的就是告诉PyInstaller将底图数据添加到分发中。这是一些示例代码。假设您在目录E:\ scratch中有一个ortho.py文件,将以下ortho.spec放在同一目录中并将其作为
运行PyInstaller -y ortho.spec
这是ortho.spec:
a = Analysis(['ortho.py'],
pathex=['E:\\scratch'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='ortho.exe',
debug=False,
strip=None,
upx=True,
console=True )
import mpl_toolkits.basemap
import os
src_basedata = os.path.join(mpl_toolkits.basemap.__path__[0], "data")
tgt_basedata = os.path.join('mpl_toolkits', 'basemap', 'data')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas + Tree(src_basedata, prefix=tgt_basedata),
strip=None,
upx=True,
name='ortho')