【发布时间】:2014-07-28 15:38:34
【问题描述】:
我正在尝试为 Python3.4 中的某些代码创建可执行文件,以分发到 Windows。该程序的某些映射功能需要 GDAL,但它在 cx_Freeze 构建期间出现在 Missing Modules 中:
Missing modules:
? _gdal imported from osgeo, osgeo.gdal
? _gdal_array imported from osgeo.gdal_array
? _gdalconst imported from osgeo.gdalconst
? _ogr imported from osgeo.ogr
? _osr imported from osgeo.osr
cx_Freeze .exe 仍然可以构建,但是当我尝试运行它时,我自然会得到:
ImportError: No module named '_gdal'
下面是我的设置脚本:
import sys
from cx_Freeze import setup, Executable
application_title = "Parametric_Price" #what you want to application to be called
main_python_file = "ParamMain.py" #the name of the python file you use to run the program
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["atexit","re","osgeo.ogr"]
packages = ["osgeo"]
# includeFiles =
build_exe_options = {"packages": packages, "includes": includes}
setup(
name = application_title,
version = "0.1",
description = "Parametric pricing tool using historical earthquake, hurricane datasets",
options = {"build_exe" : build_exe_options },
executables = [Executable(main_python_file, base = base)])
我尝试了各种方法来手动包含模块,使用包含在 cx_Freeze 设置文件的 build_exe 选项中,但无济于事,并且在 Python3 上确实限制了我对替代可执行分发工具的选择。有谁知道如何解决这个导入问题?
【问题讨论】:
-
如果您在 Python shell 中执行
import _gdal和print _gdal,您会看到什么? -
@ThomasK 它导入没有错误,我可以访问它的功能。在程序本身中,我通过 osgeo.ogr、osgeo.osr 间接导入它,它在那里也能正常工作。我相信这个问题是我的 cx_Freeze 设置所特有的。
-
我明白了。但是
print _gdal应该会告诉你它是从哪里加载的,这可能会为 cx_Freeze 找不到它的原因提供线索。
标签: python python-3.x cx-freeze gdal