自从PyCharm 2019更新以来,我无法加载QGIS Python模块。我也不能使用自动完成功能。我已经删除了缓存(通过使PyCharm中的缓存无效并且还通过删除用户设置目录中的“ system”文件夹),似乎没有任何作用。
在PyCharm中启动Python控制台并键入“ import qgis.core”时,出现以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\OSGEO4~1\apps\qgis-ltr\python\qgis\core\__init__.py", line 27, in <module>
from qgis._core import *
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
在PyCharm 2018.3中似乎有些问题,一切正常。sys.path环境和解释器设置似乎正确:
['C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\pydev',
'C:\\OSGEO4~1\\apps\\qgis-ltr\\python',
'C:\\OSGEO4~1\\apps\\qgis-ltr\\python\\plugins',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\third_party\\thriftpy',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\pydev',
'C:\\OSGeo4W64\\apps\\Python37\\python37.zip',
'C:\\OSGEO4~1\\apps\\Python37\\DLLs',
'C:\\OSGEO4~1\\apps\\Python37\\lib',
'C:\\OSGeo4W64\\apps\\Python37',
'C:\\OSGEO4~1\\apps\\Python37',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\win32',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\win32\\lib',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\Pythonwin']
有没有人将PyCharm更新到2019年并且可以确认这一点?我还重新安装了整个QGIS安装程序,但似乎没有任何效果。
看起来包含存根的DLL现在不兼容?
我启动PyCharm的方法如下:
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.4.2\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.4.2\lib
path %PATH%;%OSGEO4W_ROOT%\apps\Qt5\bin
path %PATH%;%OSGEO4W_ROOT%\apps\Python37\Scripts
path %PATH%;C:\Program Files\Docker\Docker\Resources\bin
path %PATH%;C:\Program Files\7-Zip
set QT_PLUGIN_PATH=C:\OSGeo4W64\apps\Qt5\plugins
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\python
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\python\plugins
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\bin\pycharm64.exe" %*
C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\bin\pycharm64.exe
指向您的新PyCharm 2019?
asyncio
库时却遇到了此类问题。我发现我在根目录C:\OSGeo4W64\lib
和边目录lib中安装了两个相同的库C:\OSGeo4W64\apps\Python37\lib
。删除侧面lib安装(使用PyCharm)后,问题已解决。但是您的问题并不完全相同。
*.bat
用于运行PyCharm的文件,该文件与QGIS兼容。