使用Pyinstaller创建的Python可执行文件由于GDAL而失败

发布于 2025-01-27 04:41:37 字数 1382 浏览 2 评论 0原文

我正在尝试从Python项目中创建使用Pyinstaller的可执行文件。该项目使用Osgeo模块GDAL和OSR:

from osgeo import gdal
from osgeo import osr

Pyinstaller成功运行,但是当我尝试执行文件时,我会遇到以下错误:

trackback(最近的最新通话):文件“ osgeo_ init _。py”,line 29,在swig_import_helper文件中 import_module文件“”,第1030行,在 _gcd_import文件“”,第1007行,在_find_and_load文件中“”,第984行,in _find_and_load_unlocked modulenotfounderror:no模块名为'osgeo._gdal'

在处理上述例外时,发生了另一个例外:

trackback(最近的最新通话):文件“ [...]。py”,第1行 文件“ pyinstaller \ loader \ pyimod03_importers.py”,第495行, 在exec_module文件中“ [...] _ init _。py”,第1行,在文件中 “ pyinstaller \ loader \ pyimod03_importers.py”,第495行,exec_module
文件“ [...] \ geomap.py”,第1行,在文件中 “ pyinstaller \ loader \ pyimod03_importers.py”,第495行,exec_module
文件“ osgeo_ init _。py”,第45行,在文件中 “ osgeo_ init _。py”,第41行,在swig_import_helper inderterror中: Trackback(最近的最新通话):文件“ Osgeo_ init _。py”,line 29,在swig_import_helper文件中 import_module文件“”,第1030行,在 _gcd_import文件“”,第1007行,在_find_and_load文件中“”,第984行,in _find_and_load_unlocked modulenotfounderror:no模块名为'osgeo._gdal'

在Windows上,带有Python> = 3.8,DLL不再从 小路。如果gdalxxx.dll在路径中,请设置 use_path_for_gdal_python =是馈送路径的环境变量 进入OS.ADD_DLL_DIRECTORY()。 [3268]无法执行脚本'[已删除 名称]”'由于没有例外!

我正在使用Python 3.9和Pyinsatller 5.0.1,GDAL 3.4.2。

有人遇到了类似的问题并找到了解决方案吗?

I am trying to create an executable with pyinstaller from a python project. The project uses osgeo modules gdal and osr:

from osgeo import gdal
from osgeo import osr

pyinstaller runs successfully, but when I try to execute the file I encounter the following errors:

Traceback (most recent call last): File "osgeo_init_.py", line
29, in swig_import_helper File "importlib_init_.py", line 127, in
import_module File "", line 1030, in
_gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'osgeo._gdal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "[...].py", line 1, in
File "PyInstaller\loader\pyimod03_importers.py", line 495,
in exec_module File "[...]_init_.py", line 1, in File
"PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "[...]\GeoMap.py", line 1, in File
"PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "osgeo_init_.py", line 45, in File
"osgeo_init_.py", line 41, in swig_import_helper ImportError:
Traceback (most recent call last): File "osgeo_init_.py", line
29, in swig_import_helper File "importlib_init_.py", line 127, in
import_module File "", line 1030, in
_gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'osgeo._gdal'

On Windows, with Python >= 3.8, DLLs are no longer imported from the
PATH. If gdalXXX.dll is in the PATH, then set the
USE_PATH_FOR_GDAL_PYTHON=YES environment variable to feed the PATH
into os.add_dll_directory(). [3268] Failed to execute script '[removed
name]' due to unhandled exception!

I am using Python 3.9 and pyinsatller 5.0.1, gdal 3.4.2.

Has anyone encountered a similar problem and found a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文