脚本运行正常但是当我使用cx_freeze冻结它时会出现cx_freeze错误。
消息末尾的说
OSError:找不到proj数据目录。期待它:C:\ python34 ........ mpl_toolkits \ basemap \ data
数据是否未包含在cx_freeze创建的构建目录中?
我使用以下脚本进行冻结
base = None
def find_data_file(pyproj):
if getattr(sys,'XXXXs.exe',False):
datadir = os.path.dirname(sys.aaEjecutable.py)
else:
datadir = os.path.dirname(__file__)
return os.path.join(datadir,pyproj)
if (sys.platform == "win32"):
base = "Win32GUI"
exe = Executable(
script = "Conver.py",
icon = "logo4.ico",
targetName = "XXXXs.exe",
base = base
)
includefiles = ["Logo1.jpg","Logo2R.jpg","Logo2R.jpg","logo4.ico",
(('C:\Python34\Lib\site-packages\mpl_toolkits'),("mpl_toolkits"))]
setup(
name = "Conver",
version = "V3",
description = "conve",
author = "Jose ",
options = {"build_exe": {"include_files":includefiles}},
executables = [exe]
)
我觉得有点不对劲。我必须包含底图,但我不知道该怎么做
我无法前行。脚本很好,但我可以在没有python的计算机中使用它
由于
答案 0 :(得分:0)
我使用Python 3.4和cx_freeze 4.3.3得到了类似的问题。我的修复需要2个更改:
在cx_freeze设置脚本中:
buildOptions = dict( include_files = [("C:/Python34/Lib/site-packages/mpl_toolkits/basemap/data","data")])
在我使用底图的模块中:
import sys, os
if getattr(sys, 'frozen', False):
os.environ['BASEMAPDATA'] = os.path.join(os.path.dirname(sys.executable), 'data')
from mpl_toolkits.basemap import Basemap
根据要求,我的完整设置脚本是:
from cx_Freeze import setup, Executable
buildOptions = dict(packages = ['osgeo._gdal'], excludes = [], \
include_files = [("C:/Python34/Lib/site-packages/mpl_toolkits/basemap/data","data")])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('main.py', base=base, targetName = 'xxxxxxx.exe', icon='ico/xxxxx.ico')
]
setup(name='Xxxxx',
version = '0.0.1',
description = 'Xxxxx xxxx xxxx',
author = 'xxxxxxx@xxx.edu',
options = dict(build_exe = buildOptions),
executables = executables)
答案 1 :(得分:0)
总是获取底图数据目录的方法,没有硬编码
import matplotlib
from mpl_toolkits import basemap
build_options = dict( include_files = [(basemap.basemap_datadir, 'data')])