TransWikia.com

import qgis.core, dll not Found

Geographic Information Systems Asked by Carmel Han on March 24, 2021

in the ‘System Variables’ i set

Path =C:OSGeo4W64appsqgisbin

This is where the ‘qgis_core.dll’ is located.

PYTHONPATH=C:OSGeo4W64appsqgispython

But when i import qgis.core i get:

   run o-help for a list of available commands
C:>python
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:OSGeo4W64appsqgispythonqgis__init__.py", line 27, in <module>
    from qgis.core import QgsFeature, QgsGeometry
  File "C:OSGeo4W64appsqgispythonqgiscore__init__.py", line 30, in <module>
    from qgis._core import *
ImportError: DLL load failed: %1 is not a valid Win32 application.
>>>

When I change the paths to osGeo4W directories (Rather then the osGeo4W64) I get:

run o-help for a list of available commands
C:>python
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:OSGeo4Wappsqgispythonqgis__init__.py", line 27, in <module>
    from qgis.core import QgsFeature, QgsGeometry
  File "C:OSGeo4Wappsqgispythonqgiscore__init__.py", line 30, in <module>
    from qgis._core import *
ImportError: DLL load failed: The specified module could not be found.
>>>

Can sombody understand what I’m doing wrong?

4 Answers

Your system python appears to be different. It is 2.7.4 32-bit.

C:OSGeo4W64appsqgispython is a 64-bit instance.

I do not recommend trying to make the python that ships with QGIS your system python - this is possible to a degree but you run the chance of creating more problems than fixing.

Instead I suggest just using the OSGeo shell that comes with the Windows installation. It can be found under pathtoosgeo4wOSGeo4W.bat and is meant for exactly this purpose.

Start this, and you will have a scripted command shell from which you can now call qgis.core:

C:Usersusername>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSV v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
>>>

Answered by auslander on March 24, 2021

I found a simple solution using OSGeo4W. In the main QGIS folder you can find a batch script named OSGeo4W.bat that define a lot of environment variables including PATH, PYTHONPATH, GDAL_DATA, etc. After that you can run o-help in order to see all the available commands. One of those commands is `python-qgis-ltr`` or similar that allow you to get a python console supporting all the QGIS libraries.

Certainly you can install other utilities (like IPython) in order to have a more convenient command interface.

Answered by Jose Munoz on March 24, 2021

What it worked for me was to check the environment paths (for path in sys.path) in the QGIS Python ("C:Program FilesQGIS 3.10appsPython37python.exe") and then add them to 'PYTHONPATH', so they are available to other python interpreters. It is recommended though to do it at runtime to avoid potential conflicts.

Answered by Raúl on March 24, 2021

I have multiple python installations. Found this method worked:

Start OSGeo shell (part of QGIS 3.16 windows install)

Start python's interactive prompt with C:>python-qgis

If I started python with C:>python, the wrong python installation started.

You can run a python script in the OSGeo shell: C:>python-qgis -i E:test.py

Answered by Rob on March 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP