lutraconsulting / ostranslator-ii

A graphical QGIS plugin for loading Ordnance Survey MasterMap into PostGIS.
16 stars 8 forks source link

Using os-translator-ii-cli.py in automation #57

Open Arawn-Davies opened 1 year ago

Arawn-Davies commented 1 year ago

Hello, I'm trying to automate the import of OS MasterMap Typography layers in PostGIS without using the QGIS UI directly. I have OSGeo4W, Python, QGIS and all required tools installed, but when running python os-translator-ii-cli.py --osmm-data-type "OS Mastermap Topography (v9)" --input-path <gz files> --host <hostname> --database <db> --user <user> --schema <schema>

it gives the error

H:\ostranslator-ii\OSTranslatorII>python os-translator-ii-cli.py
Traceback (most recent call last):
  File "H:\ostranslator-ii\OSTranslatorII\os-translator-ii-cli.py", line 25, in <module>
    from .import_manager import ImportManager
ImportError: attempted relative import with no known parent package

H:\ostranslator-ii\OSTranslatorII>

Now, as a workaround I've removed the prefixing dot from each import, as there is no parent package. That works, but I'm wondering if there is a less-hacky method to running the CLI script directly from a command line window.

My python env variables are:

PYTHONHOME=C:\PROGRA~1\QGIS31~1.5\apps\Python39
PYTHONPATH=C:\Program Files\QGIS 3.16.5\apps\qgis-ltr\python;C:\Users\ardavies\Desktop\ostranslator-ii\

as QGIS's python modules needed to be in PYTHONPATH to import the qgis QT and other python modules.

rjwats commented 1 year ago

It looks like running this from the module might be what you need. Assuming the module is somewhere on the python path:

python -m OSTranslatorII.os-translator-ii-cli

image