10

Since the update to PyCharm 2019 I am unable to load the QGIS Python modules. I can not use auto completion either. I already deleted the cache (by invalidating the cache in PyCharm and also by deleting the "system" folder in the user settings directory), nothing seems to work.

When starting the Python console inside of PyCharm and typing "import qgis.core", I get the following error:

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.

Something seems to be broken, in PyCharm 2018.3 everything was ok. The sys.path environments and interpreter settings seem to be correct:

['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']

Has anyone updated PyCharm to 2019 and can confirm this? I also reinstalled the whole QGIS installation, but nothing seems to work.

It looks like the DLLs containing the stubs are incompatible now?

My bat for starting PyCharm looks like this:

@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" %*
  • Show me your *.bat file that you use to run PyCharm, compatible with QGIS. – Mr. Che Apr 1 at 11:04
  • C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\bin\pycharm64.exe points to your new PyCharm 2019? – Mr. Che Apr 1 at 11:31
  • yes it does.. PyCharm is starting, but it seems to be unable to load the qgis DLLs – TheGrudge Apr 1 at 11:35
  • I tried to set the PYTHONHOME in C:\OSGeo4W64\etc\ini\python-core.bat to C:\OSGeo4W64\apps\Python37 as well, but nothing seems to work. – TheGrudge Apr 1 at 11:36
  • I used to have such problems with DLLs, but with additional asyncio libraries. I found that I installed double identical libraries in the root directory C:\OSGeo4W64\lib and the side directory lib C:\OSGeo4W64\apps\Python37\lib. After removing the side lib installation (using PyCharm), the problem was resolved. But your problem is not identical. – Mr. Che Apr 1 at 11:42
2

I use such *.cmd file (different than yours) to start PyCharm. Try to use it.

@ECHO off

set OSGEO4W_ROOT=C:\OSGeo4W64

call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2018.3\bin\pycharm64.exe"

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH%

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "PyCharm aware of QGIS" /B %PYCHARM% %*
  • I took your bat file and only changed the path to pycharm, but unfortunately it is not working. I invalidated the cache again and re-indexed the project, but the QGIS imports are not working (the same DLL load error) – TheGrudge Apr 1 at 13:06
  • could this be a problem: PyDev console: starting. Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 sys.platform 'win32' I've just seen that the python console seems to think it is running on win32 – TheGrudge Apr 1 at 14:15
  • @user782457 Here is my python startup message (same as yours): PyDev console: starting. Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 – Mr. Che Apr 2 at 4:09
  • yeah I guess Python under Windows is not telling you the correct architecture, there seems to be other modules that can print the correct information. Anyway I installed QGIS 3.4.6 with the netinstaller and PyCharm 2019 on a new machine, and I'm still unable to load the DLLs. So it doesn't seem to be a problem with my installation. – TheGrudge Apr 2 at 8:05
1

Edit 1: Seems to be only a PyCharm 2019.1 issue. As a temporary solution the start-script works fine with PyCharm 2018.3.6, wich can be downloaded from https://www.jetbrains.com/pycharm/download/previous.html

This errors occurs with PyCharm Professional 2019.1 as well, but it is possible to import the qgis modules from a "normal" python that was started with the same startup script / environmental settings as described above:

set OSGEO4W_ROOT=C:\Program Files\QGIS 3.6
set PYCHARM="C:\Program Files\JetBrains\PyCharm 2019.1.1\bin\pycharm64.exe"
@ECHO off

call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH%

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

:: A python able to call "import qgis.core"
start python

:: A python unable to call "import qgis.core"
start "PyCharm unfortunatelley not-aware of QGIS" /B %PYCHARM% %*
0

This Stack Overflow answer points to there being a known PyCharm issue (with Anaconda at least) in PyCharm 2019.1 causing the ImportError: DLL load failed: The specified module could not be found issue.

It's intended to be fixed in PyCharm 2019.1.2

  • Unfortunately it is still present in 2019.1.3 – TheGrudge Jun 5 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.