Skip to content

Cannot load Dll/Pyd from QGIS #2059

@Tiehong

Description

@Tiehong

Environment

  • Pythonnet version: 3.0 (64 bit)
  • Python version: 3.9 (64 bit)
  • Operating System: Windows 11
  • .NET Runtime: Net Framework 4.7.2

Details

  • Describe what you were trying to get done.

    I was trying to use some QGIS functions (64 bit).

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

Here is my code. You will need to download and install QGIS3.8.2.

import os
import ctypes

p = r'C:\PROGRA1\QGIS321.2\apps\qgis\bin;C:\PROGRA1\QGIS321.2\apps\grass\grass78\lib;C:\PROGRA1\QGIS321.2\apps\grass\grass78\bin;C:\PROGRA1\QGIS321.2\apps\qt5\bin;C:\PROGRA1\QGIS321.2\apps\Python39;C:\PROGRA1\QGIS321.2\bin'#;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem'
lst=p.split(';')
lst.append(r'C:\WINDOWS')
lst.append(r'C:\WINDOWS\sysWOW64')
for f in lst:
os.add_dll_directory(f)

os.environ["PATH"]=';'.join(lst)

ctypes.WinDLL(r"C:\Program Files\QGIS 3.28.2\apps\qgis\python\qgis_core.pyd")

  • If there was a crash, please include the traceback here.

An error was thrown at ctypes.WinDLL():

[WinError 193] %1 is not a valid Win32 application
File "C:\Program Files\QGIS 3.28.2\apps\Python39\Lib\ctypes_init_.py", line 374, in init

The same code runs OK in Python3.9 64 bit. I wonder if Python runtime was trying to load a 32 bit DLL while a 64 bit DLL with the same file name exists. If that's the case, is there an option to prioritize the 64 bit DLL?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions