TransWikia.com

Compatibilty issue of pyexiv2 and ctypes module in QGIS 3.10

Geographic Information Systems Asked by zlikotp on October 25, 2020

I’m trying to install a python module called pyexiv2 onto QGIS 3.10, I’ve noticed this module doesn’t work. Although the module’s installation seems to process well python -m install pyexiv2
and I get confirm the installation was done. Requirement already satisfied: pyexiv2 in c:progra~1qgis3~1.10appspython37libsite-packages (1.3.0) , we are not able to import pyexiv2 in PyQGIS without getting an error :

OSError: [WinError 127] The specified procedure could not be found

I’ve tried OSGeo4W network installation, QGIS 3.10 standalone but nothing works, exept with QGIS 3.4 : this issue only appears from QGIS 3.10

As suggested I’ve tried the p3exiv2 module but the PYPI package is not designed for iOS & Linux only, that is why it seems not possible to install it. Except… by using another p3exiv2 module adapted for windows but this one requires some Windows packages like GIT & VCPKG (MS Visual Studio)… and I was not able to install it.

I’ve then contacted pyexiv2‘s author and he found where the issue was from. We are waiting for a new version of pyexiv2 next month that may (or may not) solve the issue.

Bug Recurrence Steps

  1. Install pyexiv2 using the Python interpreter that comes with QGIS3.10 : "C:Program FilesQGIS 3.10appsPython37python.exe" -m pip install pyexiv2

  2. I can execute the following command successfully, in the Python interpreter that comes with QGIS3.10 ::

     C:UsersLeo>"C:Program FilesQGIS 3.10appsPython37python.exe"
     Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
     Type "help", "copyright", "credits" or "license" for more information.
     >>> import os
     >>> import ctypes
     >>> dll_dir = r'C:Program FilesQGIS 3.10appsPython37Libsite-packagespyexiv2lib'        # This is where pyexiv2 is installed
     >>> ctypes.CDLL(os.path.join(dll_dir, "exiv2.dll"))
     <CDLL 'C:Program FilesQGIS 3.10appsPython37Libsite-packagespyexiv2libexiv2.dll', handle 7ffe9ad90000 at 0x23702c3b9e8>
     >>> ctypes.CDLL(os.path.join(dll_dir, "api.dll"))
     <CDLL 'C:Program FilesQGIS 3.10appsPython37Libsite-packagespyexiv2libapi.dll', handle 7ffee1920000 at 0x23702c55908>
    
  3. But I failed to execute the same code in the GUI of QGIS3.10 :

     Python Console
     Use iface to access QGIS API interface or Type help(iface) for more info
     Security warning: typing commands from an untrusted source can lead to data loss and/or leak
     import os
     import ctypes
     dll_dir = r'C:Program FilesQGIS 3.10appsPython37Libsite-packagespyexiv2lib'
     ctypes.CDLL(os.path.join(dll_dir, "exiv2.dll"))
     <CDLL 'C:Program FilesQGIS 3.10appsPython37Libsite-packagespyexiv2libexiv2.dll', handle 7ffea62d0000 at 0x26cd89b0860>
     ctypes.CDLL(os.path.join(dll_dir, "api.dll"))
     Traceback (most recent call last):
      File "C:PROGRA~1QGIS3~1.10appsPython37libcode.py", line 90, in runcode
       exec(code, self.locals)
      File "<input>", line 1, in <module>
      File "C:PROGRA~1QGIS3~1.10appsPython37libctypes__init__.py", line 356, in __init__
       self._handle = _dlopen(self._name, mode)
     OSError: [WinError 127] The specified procedure could not be found.
    

Conclusion :

The reason may be that the DLL used by QGIS3.10 conflicts with ctypes.
The author is going release a new version of pyexiv2 that could solve the issue but nothing sure.
I don’t know how we can report this issue to QGIS team and if we should?

About using py3exiv2 instead of pyexiv2 : that could be another solution but I failed (but I’m newbie !).

One Answer

I have the same problem with pyexiv2, I can install, but when I import the library script crash.

I found a solution using the library exif:

https://pypi.org/project/exif/

It's so easy to use, and with Qgis I don,'t have any problem.

In this code I insert GPS coordinates to a snapshot of screen:

from exif import Image
with open(file_name, 'rb') as image_file:
    my_image = Image(image_file)

my_image.make = "Python"
my_image.gps_latitude_ref=exif_lat_ref
my_image.gps_latitude=exif_lat
my_image.gps_longitude_ref= exif_lon_ref
my_image.gps_longitude= exif_lon

with open(file_name, 'wb') as new_image_file:
    new_image_file.write(my_image.get_file())

Answered by RBenet on October 25, 2020

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