从qgis.core导入QgsFeature、QgsGeometry时DLL加载失败

0 投票
3 回答
3964 浏览
提问于 2025-04-18 08:49

我最近安装了QGIS,想要在Python中导入qgis模块。我使用的是Windows 7 x64和QGIS 2.2 x64。我把PATH设置成了:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\mapnik-v2.2.0\lib;C:\mapnik-v2.2.0\bin;C:\Program Files (x86)\QGIS Valmiera\apps\qgis\python;C:\OSGeo4W\bin;E:\Python\GeoDjango\myplanet;E:\Python\GeoDjango\myplanet;C:\Program Files (x86)\QGIS Valmiera\bin;C:\Program Files (x86)\QGIS Valmiera\apps\msys\bin;C:\Program Files (x86)\QGIS Valmiera\apps\Python27;C:\Program Files (x86)\QGIS Valmiera\bin;C:\Program Files (x86)\QGIS Valmiera\apps\qgis\python\qgis;

并把PYTHONPATH设置成了:

C:\mapnik-v2.2.0\python\2.7\site-packages;E:\Python\GeoDjango\myplanet;C:\Program Files\QGIS Valmiera\apps\qgis\python;C:\Program Files\QGIS Valmiera\apps\Python27\lib;C:\Program Files\QGIS Valmiera\apps\Python27\Lib\site-packages;C:\Program Files\QGIS Valmiera\apps\Python27\DLLs;

但是我还是遇到了这个错误:

    import qgis
  File "C:\Program Files\QGIS Valmiera\apps\qgis\python\qgis\__init__.py", line 35, in <module>
    from qgis.core import QgsFeature, QgsGeometry
ImportError: DLL load failed: The specified module could not be found.

我使用了Dependency Walker来追踪DLL加载的问题。这是Dependency Walker的截图:

enter image description here
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

我该如何修复这些错误呢?

3 个回答

-1

我刚开始学习Python(还有QGIS),但我在指南里看到qgis.core不是一个dll文件。这里的“qgis”是一个文件夹,而“core.pyd”是一个文件。你需要把包含qgis文件夹的路径添加到你的PYTHONPATH变量中。对我来说,这个路径是:PYTHONPATH="C:\Program Files\QGIS Valmiera\apps\qgis\python"。希望这些信息对你有帮助!!

0

我现在使用PyCharm作为我的开发工具,我的解决办法是把“python-qgis.bat”设置为Python解释器,这个.bat文件的路径是“~\qgis\bin”。查看这个.bat文件,你会发现里面已经设置好了所有的路径。希望这对你有帮助。

0

请查看这里: 使用PyQGIS时DLL加载失败

import sys
sys.path.extend([r"C:\Program Files\QGIS Valmiera\apps",r"C:\Program Files\QGIS Valmiera\apps\qgis\bin",r"C:\Program Files\QGIS Valmiera\apps\Python27"])

import qgis.core

撰写回答